URL Routing System-namespace

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.