django2.0新特性在url中的配置

在1.0中

url(r'^',include('third.urls'))

在2.0中

path('',include('third.urls'))

并且导入包

from django.urls import include, path

在app中的url配置中

导入   from third import views   

path('index',views.index)

在2.0中不需要写^匹配开头,默认从开头开始匹配,结尾也不用写$符号,默认到结尾

django的例子

Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))

 以下的url配置在django2.0中是通用的:

    url(r'^user/',include('user.urls',namespace='user')),

 

path('',include(('user.urls','user'),namespace='user')),# 反向解析
 

你可能感兴趣的:(django)