zoukankan      html  css  js  c++  java
  • day62 作业

    熟练使用无名有名分组

    urls.py

     url(r'^edit/(d+)/',views.edit_user,name='edit'),
    

    views.py

    def edit_user(request,edit_id):
    
        edit_obj = models.Author.objects.filter(id=edit_id).first()
        if request.method == 'POST':
            username = request.POST.get('username')
            password = request.POST.get('password')
            # 第一种更新操作,全部更新
            models.Author.objects.filter(id=edit_id).update(username=username,password=password)
            # 第二种更新,拿到数据对象再更新,这种更新方式在字段多的时候会效率很慢
            edit_obj.username = username
            edit_obj.password = password
            edit_obj.save()
    
            return redirect('/userlist/')
        return render(request,'edit.html',locals())
    
    

    userlist.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <link href="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
        <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
    
    </head>
    <body>
    
    <div class="container">
        <div class="row">
            <div class="col-lg-8">
                <table class="table table-striped table-hover text-center">
                    <thead>
                        <tr>
                            <th class="text-center">id</th>
                            <th class="text-center">username</th>
                            <th class="text-center">password</th>
                            <th class="text-center">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for obj in user_queryset %}
                            <tr>
                                <td>{{ obj.id }}</td>
                                <td>{{ obj.username }}</td>
                                <td>{{ obj.password }}</td>
                                <td>
                                    <a href="{% url 'edit' obj.id %}" class="btn-xs btn-success">编辑</a>
                                    <a href="/user_delete/?id={{ obj.id }}" class="btn-xs btn-danger">删除</a>
                                </td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    
    </body>
    </html>
    
  • 相关阅读:
    样式表中!important的用法
    ORA27101: shared memory realm does not exist问题的解决
    重置标识列的当前值
    ASP.NET Oracle数据库使用事务时注意事项
    Oracle中约束的添加方法总结
    HTML段落自动换行的样式设置
    ASP.NET应用程序中的服务器错误
    oracle中的rownum、order by与分页
    position:relative与float的区别
    Moss/Sharepoint 备份或还原时出错的处理(持续更新)
  • 原文地址:https://www.cnblogs.com/hz2lxt/p/12977055.html
Copyright © 2011-2022 走看看