The Django Book:第8章 高级视图和URL配置
第3章我们解释了Django视图方法和URL配置基础,本章将对这两部分进行详述
URL配置技巧
使方法import流化
看看下面的URL配置,基于第3章的例子:
代码from django.conf.urls.defaults import * from mysite.views import current_datetime, hours_ahead, hours_behind, now_in_chicago, now_in_london urlpatterns = patterns('', (r'^now/$', current_datetime), (r'^now/plus(\d{1,2})hours/$', hours_ahead), (r'^now/minus(\d{1,2})hours/$', hours_behind), (r'^now/in_chicago/$', now_in_chicago), (r'^now/in_london/$', now_in_london), )
注意额外选项将一直传递给include的URL配置的每一行,而不管那一行的视图是否认为是合法的选项
由于这个原因,这项技术仅仅当你确认在include的URL配置里每个视图接受你传递的选项时才是有用的
视图技巧
This Chapter is not yet finished on http://www.djangobook.com |