Python's rookie path: Django routing, templates, ORM

Source: Internet
Author: User

Django Routing System

The Django routing system allows Django to match the URI and send it to a specific function to process the user request. A bit like Nginx's location function.

The Django routing relationship is divided into three types: normal, dynamic, and group distribution. These three relationships are recorded in urls.py.

Routing-common Relationship

A normal relationship represents a URL that corresponds to a function, for example:

urlpatterns = [url (r '    ^admin/', admin.site.urls),    url (r ' ^login/', views.login),    url (r ' ^detail/', Views.detail),]

Routing-Dynamic Relationships

The dynamic relationship means that the dynamic matching is realized by means of regularization. For example:

Urlpatterns = [    url (R ' ^detail/(\d+)/', views.detail),  # Dynamic routing: A single-parameter routing    URL (r ' ^detail2/(\d+)/', VIEWS.DETAIL2),  # Dynamic routing: Multi-parameter Routing    URL (r ' ^detail3/(? p<p1>\d+)/(? p<x2>\d+)/', views.detail3), # Dynamic routing: named parameter, two parameters are named P1 and X2    url (r ' ^index/(\d+)/', Views.index),  # pagination display ]

Dynamic routing can also be implemented by mapping

Routing-Packet Distribution

Python's rookie path: Django routing, templates, ORM

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.