Boo*_*ap4 3 python django http
request.GET.get是什么意思?我在Django看到类似的东西
page = request.GET.get('page', 1)
Run Code Online (Sandbox Code Playgroud)
我认为这与某些事情有关
<li><a href="?page={{ users.previous_page_number }}">«</a></li>
Run Code Online (Sandbox Code Playgroud)
他们是如何工作的?
小智 5
request.GET是GET服务器发出的http请求中变量的字典,例如:
www.google.com?thisIsAGetVarKey=3&thisIsAnotherOne=hello
Run Code Online (Sandbox Code Playgroud)
request.GET 将会: {"thisIsAGetVarKey": 3, "thisIsAnotherOne":"hello"}
因为request.GET是字典,所以它具有.get()检索字典中键值的方法
dict_b = {'number': 8, 'alphabet':'A'}
print dict_a['number'] #prints 8
print dict_a.get('alphabet') #prints A
print dict_a['bob'] #throws KeyError
print dict_a.get('bob') #prints None
print dict_a.get('bob', default=8) #prints 8
Run Code Online (Sandbox Code Playgroud)