request.GET.get是什么意思? [英] What does request.GET.get mean?
问题描述
request.GET.get是什么意思?我在Django中看到了类似的内容
What does request.GET.get mean? 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是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!