Name space
1. urs.py under the project Django
from django.conf.urls import url,include from django.urls import path,re_pathurlpatterns = [Path ( " admin/ " cmdb/ ", include (" cmdb.urls " Span style= "COLOR: #ff0000" >namespace= ' CMDB ' )),
Path ('app/', include ("cmdb.urls", Namespace= ' app '),
]# two ur 127.0.0.1/cmdb/ 127.0.0.1/app/ also point to a URL under a CMDB
2. urls.py under the CMDB in the project
from Import Views
appname= ' CMDB ' #这个appname需要设置 = [ path ('login/', Views.login,name="login"),]# is two URLs 127.0.0.1/ Cmdb/login and 127.0.0.1/app/login simultaneously point to the login function in the CMDB
3.cmdb in views.py
from Import Httpresponse,render
from Import Reverse
def Login (Request): v=reverse ('CMDB ': ' login ') to reverse-generate URL based on namespace and name
Print (v)
return HttpResponse ('ok')
app01.views.py
123 |
def detail (Request, PK):
    
print
(Request.resolver_match)
    
return HttpResponse(pk)
|
URL Routing System-namespace