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