码迷,mamicode.com
首页 > 其他好文 > 详细

django中request的POST小记

时间:2019-02-26 15:03:57      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:checked   color   htm   pos   NPU   name   res   pre   ret   

views.py

from django.http import HttpResponse

def postTest1(request):
    return render(request, booktest/postTest1.html)


def postTest2(request):
    uname = request.POST[uname]
    upwd = request.POST[upwd]
    ugender = request.POST[ugender]
    uhobby = request.POST.getlist(uhobby)
    context = {uname: uname, upwd: upwd, ugender: ugender, uhobby: uhobby}
    return render(request, booktest/postTest2.html, context)

urls.py

from booktest import views
from django.urls import path

urlpatterns = [
    path(postTest1/, views.postTest1),
    path(postTest2/, views.postTest2),

]

postTest1.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form method="post" action="/booktest/postTest2/">
    用户名:<input type="text" name="uname"><br>
    密码:<input type="text" name="upwd"><br>
    性别:<input type="radio" name="ugender" value="" checked="checked"><input type="radio" name="ugender" value="">女<br>
    爱好:<input type="checkbox" name="uhobby" value="足球">足球
            <input type="checkbox" name="uhobby" value="篮球">篮球
            <input type="checkbox" name="uhobby" value="毛球">毛球<br>
    <input type="submit" value="提交">
<!--post请求中 name属性作为键提交 value属性作为值提交 -->
</form>
</body>
</html>

postTest2.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
用户名:{{ uname }}<br>
密码:{{ upwd }}<br>
性别:{{ ugender }}<br>
爱好:{{ uhobby }}
</body>
</html>

 

django中request的POST小记

标签:checked   color   htm   pos   NPU   name   res   pre   ret   

原文地址:https://www.cnblogs.com/gaota1996/p/10437275.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!