问题描述
request.GET.get是什么意思?我在Django中看到类似的东西
What does request.GET.get means? I see something like this in Django
page = request.GET.get('page', 1)
我认为这与
<li><a href="?page={{ users.previous_page_number }}">«</a></li>
它们如何运作?
推荐答案
请求
对象包含有关用户请求的信息。他们发送到页面的数据,他们来自哪里等等。
The request
object contains information about the user's request. What data they've sent to the page, where they are coming from, etc.
request.GET
包含GET变量。这些是您在浏览器的地址栏中看到的内容。 .get()
方法是一种用于词典的方法。您的代码片段正在做的是获取名称为'page'的GET变量的值,如果它不存在,则返回1。
request.GET
contains the GET variables. These are what you see in your browser's address bar. The .get()
method is a method used for dictionaries. What your snippet of code is doing is saying, "Get the value of a GET variable with name 'page', and if it doesn't exist, return 1".
同样,当用户提交表单时,您会看到 request.POST
。
Likewise, you will see request.POST
used when a user submits a form.
您可以阅读有关GET与POST的更多信息。
You can read more about GET vs. POST here.
这篇关于request.GET.get是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!