django 1.x版本与2.x版本
URL区别
在django 1.x中的方式
导入的模块是'from django.conf.urls import url',urlpatterns中url对应的是正则表达式,如下:
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'),
在django 2.x中的方式
导入的模块是from django.urls import re_path,path
,re_path对应的是1.x版本中的url是匹配正则表达式的,而path并不匹配正则表达式
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() ),
]