from django.conf.urls import patterns, url
urlpatterns = patterns(‘‘,
url(r‘^articles/2003/$‘, ‘news.views.special_case_2003‘),
url(r‘^articles/(\d{4})/$‘, ‘news.views.year_archive‘),
url(r‘^articles/(\d{4})/(\d{2})/$‘, ‘news.views.month_archive‘),
url(r‘^articles/(\d{4})/(\d{2})/(\d+)/$‘, ‘news.views.article_detail‘),
)
(\d{4})匹配出了
2005,但2005任然会被当做字符串传递给year_archive
urlpatterns = patterns(‘‘, url(r‘^articles/2003/$‘, ‘news.views.special_case_2003‘), url(r‘^articles/(?P<year>\d{4})/$‘, ‘news.views.year_archive‘), url(r‘^articles/(?P<year>\d{4})/(?P<month>\d{2})/$‘, ‘news.views.month_archive‘), url(r‘^articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$‘, ‘news.views.article_detail‘), )
year_archive(year=‘2005‘)
# URLconf from django.conf.urls import patterns, url urlpatterns = patterns(‘‘, url(r‘^blog/$‘, ‘blog.views.page‘), url(r‘^blog/page(?P<num>\d+)/$‘, ‘blog.views.page‘), ) # View (in blog/views.py) def page(request, num="1"): # Output the appropriate page of blog entries, according to num.
from django.conf.urls import patterns, url urlpatterns = patterns(‘news.views‘, url(r‘^articles/(\d{4})/$‘, ‘year_archive‘), url(r‘^articles/(\d{4})/(\d{2})/$‘, ‘month_archive‘), url(r‘^articles/(\d{4})/(\d{2})/(\d+)/$‘, ‘article_detail‘), )
urlpatterns = patterns(‘myapp.views‘, url(r‘^$‘, ‘app_index‘), url(r‘^(?P<year>\d{4})/(?P<month>[a-z]{3})/$‘,‘month_display‘), ) urlpatterns += patterns(‘weblog.views‘, url(r‘^tag/(?P<tag>\w+)/$‘, ‘tag‘), )
from django.conf.urls import include, patterns, url urlpatterns = patterns(‘‘, # ... snip ... url(r‘^comments/‘, include(‘django.contrib.comments.urls‘)), url(r‘^community/‘, include(‘django_website.aggregator.urls‘)), url(r‘^contact/‘, include(‘django_website.contact.urls‘)), # ... snip ... )
from django.conf.urls import include, patterns, url extra_patterns = patterns(‘‘, url(r‘^reports/(?P<id>\d+)/$‘, ‘credit.views.report‘), url(r‘^charge/$‘, ‘credit.views.charge‘), ) urlpatterns = patterns(‘‘, url(r‘^$‘, ‘apps.main.views.homepage‘), url(r‘^help/‘, include(‘apps.help.urls‘)), url(r‘^credit/‘, include(extra_patterns)), )
from django.conf.urls import patterns, url urlpatterns = patterns(‘blog.views‘, url(r‘^blog/(?P<year>\d{4})/$‘, ‘year_archive‘, {‘foo‘: ‘bar‘}), )
from django.conf.urls import patterns, url from mysite.views import archive, about, contact urlpatterns = patterns(‘‘, url(r‘^archive/$‘, archive), url(r‘^about/$‘, about), url(r‘^contact/$‘, contact), )
原文地址:http://blog.csdn.net/feelang/article/details/25245935