喵吉欧尼酱

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

home表单

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body style="margin: 0 auto">
        <div style="height: 48px;background-color: #dddddd;"></div>
<div>
    <div>
        <form action="/home/ " method="post">
            <input type="text" name="username" placeholder="用户名"/> #placehodleer 用来
             <input type="text" name="年龄" placeholder="年龄"/>
             <input type="text" name="email" placeholder="emeal"/>
             <input type="submit" value="添加"/>

        </form>

    </div>
    <table>
        {% for row in user_list %}#循环开始
        <tr>
            <td>{{ row.username }}</td>
         <td>{{ row.年龄 }}</td>
         <td>{{ row.email }}</td>
        </tr>
    {% endfor %} #循环借宿
    </table>
</div>


</body>
</html>

后端

USER_LIST=[
    {'username':'lihai','年龄':18,'email':'465456@qq.com'},{'username':'lihai','年龄':68,'email':'465456@qq.com'},

]


def home(request):
    if request.method=='POST':
        u=request.POST.get('username')
        e = request.POST.get('年龄')
        g = request.POST.get('email')
        temp={'username':u,'年龄':e,'email':g}
        USER_LIST.append(temp)

    return render(request,'home.html',{'user_list':USER_LIST}) #将user_list 显示真个列表

 

posted on 2017-09-26 16:33  喵吉欧尼酱  阅读(123)  评论(0)    收藏  举报