django学习手记 四


                高级url视图
观察下面的视图:
               
               
                from django.conf.urls.defaults import *  
  
urlpatterns = patterns('mysite.views',  
    (r'^/?$', 'archive_index'),  
    (r'^(\d{4})/([a-z]{3})/$','archive_month'),  
)  
  
urlpatterns += patterns('weblog.views',  
    (r'^tag/(\w+)/$', 'tag'),  
)
命名组
               
                urlpatterns = patterns('',  
  (r'^articles/(?P\d{4})/$', views.year_archive),  
  
(r'^articles/(?P\d{4})/(?P\d{2})/$', views.month_archive),  
)
添加额外的信息
urlpatterns = patterns('',  
  (r'^foo/$', views.foobar_view, {'template_name': 'template1.html'}),  
  (r'^bar/$', views.foobar_view, {'template_name': 'template2.html'}),
)
伪造一个url,第一个url , 相当于/mydata/jan/06
   urlpatterns = patterns('',  
  (r'^mydata/birthday/$', views.my_view, {'month': 'jan', 'day': '06'}),  

(r'^mydata/(?P\w{3})/(?P\d\d)/$', views.my_view),  
)  
url include()
urlpatterns = patterns('',  
(r'^weblog/', include('mysite.blog.urls')),  
(r'^photos/', include('mysite.photos.urls')),  
(r'^about/$', 'mysite.views.about'),  
)