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>
    
  • 相关阅读:
    mongodb 初学 意外 连接服务器异常(Connection refused)
    mongodb 关闭服务器
    Redis 入门指令
    mongodb 在 Ubuntu系统上的安装及卸载
    Java 使用 Redis
    随笔 -- IO -- Socket/ServerSocket -- 系统概述
    java enum(枚举)使用详解 + 总结
    Java -- IO -- 目录
    Java 流(Stream)、文件(File)和IO -- Java ByteArrayInputStream类
    INSERT INTO .. ON DUPLICATE KEY UPDATE ...
  • 原文地址:https://www.cnblogs.com/hz2lxt/p/12977055.html
Copyright © 2011-2022 走看看