Django-3视图

2017-10-11  本文已影响31人  吕阳

视图

handle.png

manage.py 中test3.urls ---> test3/urls.py---->booktest/urls.py

3.2视图函数

3.3.1GET属性

def getTest1(request):
    return render(request,'booktest/getTest1.html')
def getTest2(request):
    return render(request,'booktest/getTest2.html')
def getTest3(request):
    return render(request,'booktest/getTest3.html')
url(r'^getTest1/$', views.getTest1),
url(r'^getTest2/$', views.getTest2),
url(r'^getTest3/$', views.getTest3),
<html>
<head>
    <title>Title</title>
</head>
<body>
<a href="/getTest2/?a=1&b=2">gettest2</a><br>
<a href="/getTest3/?a=1&a=2&b=3">gettest3</a>
</body>
</html>
def getTest2(request):
    a=request.GET['a']
    b=request.GET['b']
    context={'a':a,'b':b}
    return render(request,'booktest/getTest2.html',context)
<html>
<head>
    <title>Title</title>
</head>
<body>
a:{{ a }}<br>
b:{{ b }}
</body>
</html>
def getTest3(request):
    a=request.GET.getlist('a')
    b=request.GET['b']
    context={'a':a,'b':b}
    return render(request,'booktest/getTest3.html',context)
<html>
<head>
    <title>Title</title>
</head>
<body>
a:{% for item in a %}
{{ item }}
{% endfor %}
<br>
b:{{ b }}
</body>
</html>

3.3.2POST

setting注释crsf

上一篇下一篇

猜你喜欢

热点阅读