Django development 3

Django 03

@URL mapping process
  2. in Find the urlpatterns variable in ROOT_URLCONF
  3. Find matching items in urlpatterns one by one, find the first match Stop looking for
  4. to find the match, call the function in the view according to the parameters in the url
  5. can not find the match, enter the error handling
from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^$', views.home),
    # /
    # views.home(request)

    url(r'^pow/(\d+)/(\d+)/$', views.pow),
    # /pow/2/5
    # views.pow(request, 2, 5)

    url(r'^point/(?P<x>\d+)/(?P<y>\d+)/$', views.getPoint),
    # /point/3/6
    # views.getPoint(x=3, y=6)

    url(r'f/(\d+)/', view.f, {'k': 10, 'r': 3})
    # /f/10
    # views.f(1, k=10, t=3)

we can also put some url mapping in the application directory, Use the include function to include this partial mapping table.

url(r'^book/', include('book.urls'))

url(r'^(\d{1,3})$', views.showBookById)        # /book/32
url(r'(\w+)', views.showBookByName)         # /book/java