<pre name="code" class="python">#coding=utf-8 """django_book URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.8/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Add an import: from blog import urls as blog_urls 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) """ from django.conf.urls import include, url from django.contrib import admin from django.conf.urls import patterns urlpatterns = [ url(r'^admin/', include(admin.site.urls)), #可以将这种格式精简成下面patterns的前缀格式 #url(r'^books/$', "books.views.book_route", name="books_book"), #url(r'^books/(?P<key>.+)/$', "books.views.book_detail", name="books_detail"), #url(r'^contactus/$', "django_forms.views.contactus", name="django_form_contactus"), #url(r'^contactus/thanks/', "django_forms.views.thanks", name="django_form_thanks"), ] #采用pattern的写法,减少view的编写 urlpatterns += patterns("books.views", url(r'^books/$', "book_route", name="books_book"), url(r'^books/(?P<key>.+)/$', "book_detail", name="books_detail"), ) #django_forms的views urlpatterns += patterns("django_forms.views", url(r'^contactus/$', "contactus", name="django_form_contactus"), url(r'^contactus/thanks/', "thanks", name="django_form_thanks"), )