Django-url distribution, 2) alias, 3) root directory, 4) Rediect jump function:

Source: Internet
Author: User

1) Distribution of URLs:
1, first write in the path inside the global URL, and the path name you want to distribute. 2, and create a new URL file in the path you want to distribute. In the distribution of the path name inside, the global URL inside the code, copy 3, and finally in the browser when opened, the command to add your distribution path full name.

Example: the original path
Urlpatterns= [
URL (R ' ^admin/', Admin.site.urls),
URL (R ' ^article/(\d{4}/\d{2}$) ', Views.article), #match the parentheses inside the
URL (R ' ^article/(? P<YEAR>\D{4})/(? P<DAYS>\D{2}) $ ' Span style= "font-size:15px" >#
URL ( r ' ^app01/' ,include ( ' app01.urls ')
]

New path:
= [
URL (R ' ^admin/', Admin.site.urls),
# URL (r ' ^article/(\d{4}/\d{2}$) ', views.article), # matches the parentheses inside the
# URL (r ' ^article/(? P<YEAR>\D{4})/(? P<DAYS>\D{2}) $ ', views.article), # matches the parentheses inside the
URL (R ' ^login/', Views.login),
]

It's inside.
2) Alias
1' alias '%} example: Urlpatterns = [url (r'^admin/', admin.site.urls), url (r' ) ^loginsdsd/', views.login,name='log'), in HTML with aliases in place of the previous name     
3) The root directory, as its name implies, does not need to be followed by any path to directly access the data behind the URLs.
The root directory is expressed in $, urlpatterns = [    url (r'^admin/', admin.site.urls), url (r'^login/', Views.login,name='log'), url (r'^$', Admin.site.urls),] the last URL is the root directory, When you use a browser to access the page, you can directly use 127.0.0.1:8000 access, there is no need to add any path.             

4) Rediect Jump function:

 return render (Request, " login.html ") and return Rediect (  "/login.html/" return render (Request,login.html ") Just jump to login.html this page, no other action, and the URL of the call is not executed, and the path is the original path, when the user refreshed again, will be back to the original path of the page. return rediect ( ' / Login.html/ ") executes the function inside the URL, which is equivalent to calling the new function again,/login.html/  All code inside the function executes, and the path changes, and the user refreshes again without changing the         

Django-url distribution, 2) alias, 3) root directory, 4) Rediect jump function:

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.