1. 程式人生 > >django的url分發的方式

django的url分發的方式

一、一級路由

urlpatterns = [
    url(r'^upload/', views.upload,name="upload"),
    url(r'^article-site/(?P<auther>\w+)', views.article_site,name="article"),
    url(r'^login/', views.login,name="bbs_login"),
    url(r'^index/', views.index,name="bbs_index"),
    url(r'^register/', views.register,name="bbs_register"),
    url(r'^logout/', views.logout, name="bbs_logout"),
    url(r'^up_down/', views.up_down,name="up_down"),
    url(r'^add_comment/', views.add_comment,name="add_comment"),
    url(r'^comment_tree/(?P<nid>\d+)', views.comment_tree,name="comment_tree"),
    url(r'^(?P<name>\w+)/$', views.blog,name="bbs_blog"),
    url(r'^(?P<name>\w+)/(?P<tid>\d+)/$', views.article),

]

  

 

二、二級路由

    url(r'^app1/',include("app1.urls")),

  

三、路由分發,這裡還可以裡面在巢狀一層

    url(r'^cui/', (
        [url(r'^test1/', test.test1),
         url(r'^test2/', test.test2),
         url(r'^test3/', test.test3),
         ]
        ,None,None)),