Django 2.0 官方文档翻译

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('polls/', include('polls.urls')),
    path('admin/', admin.site.urls),
]

Path():

  path() 函数有四个参数,两个必选参数:route 和 view,和两个可选参数:kwargs 和 name。下面我们来看一下每个参数的作用

  参数一 route:route 是一个包含URL模式的字符串。处理 request 的时候,Django 在 urlpatterns列表中自上而下依次比较 request URL,直到找到相匹配的那个。

字符串不匹配 GET 和 POST 参数或者域名,例如 https://www.example.com/myapp/ 这个请求会在URLconf 中查找 myapp/https://www.example.com/myapp/?page=3 也会查找 myapp/

  参数二 view:When Django finds a matching pattern, it calls the specified view function with an HttpRequest object as the first argument and any “captured” values from the route as keyword arguments. We’ll give an example of this in a bit.

posted @ 2019-02-26 17:07  哈撒king  阅读(252)  评论(0编辑  收藏  举报