干净的URL非常重要,django对此提供了充分的支持。
django使用URLConf模块匹配请求的URL对应哪个function,URLConf是一个普通的python moudle。
URLConf模块实例(urls.py):
from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^articles/2003/$', 'news.views.special_case_2003'), (r'^articles/(\d{4})/$', 'news.views.year_archive'), (r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'), (r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'), )
django对接收到的请求url的路由流程: