django简化url配置

<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"),
)



                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值