django 1.x and 2.x versions version
URL difference
The way in django 1.x
Import module is 'from django.conf.urls import url', urlpatterns url in the corresponding regular expression, as follows:
from django.conf.urls import url,include
from django.contrib import admin
urlpatterns = [
url(r'^admin/$', admin.site.urls),
url(r'^crm/$', include('app01.urls',namespace='app01')),
]
# 在app01.urls中
urlpatterns = [
url(r'^login/', views.login,name='login'),
url(r'^reg/', views.reg,name='reg'),
url(r'^index/', views.index,name='index'),
# url(r'^detialinfo/', views.detialinfo,name='detialinfo'),
url(r'^customer_list/', views.CustomerList.as_view(),name='customer_list'),
url(r'^mine_customer/', views.CustomerList.as_view(),name='mine_customer'),
url(r'^customer_add/', views.customer_operate,name='customer_add'),
url(r'^customer_edit/(\d+)/', views.customer_operate,name='customer_edit'),
The way in django 2.x
Module is introduced from django.urls import re_path,path
, re_path corresponds version 1.x url match the regular expression, while the path does not match the regular expression
from django.urls import re_path,path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('students.urls')),
path('ser/', include('ser.urls')),
]
# 在ser.urls中
urlpatterns = [
path("students/", views.StudentAPIView.as_view() ),
path("students1/", views.StudentGenericAPIView.as_view() ),
path("students2/", views.Student2GenericAPIView.as_view() ),
re_path(r"^students3/(?P<pk>\d+)/$", views.Student3GenericAPIView.as_view() ),
]