三种urls的写法

第一种:

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('polls.views',
    url(r'^polls/$', 'index'),
    url(r'^polls/(?P\d+)/$', 'detail'),
    url(r'^polls/(?P\d+)/results/$', 'results'),
    url(r'^polls/(?P\d+)/vote/$', 'vote'),
)

urlpatterns += patterns('',
    url(r'^admin/', include(admin.site.urls)),
)
第二种:

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^polls/', include('polls.urls')),
    url(r'^admin/', include(admin.site.urls)),
)

第三种 直接写

urlpatterns = patterns('',
    url(r'^polls/$', 'polls.views.index'),
    url(r'^polls/(?P\d+)/$', 'polls.views.detail'),
    url(r'^polls/(?P\d+)/results/$', 'polls.views.results'),
    url(r'^polls/(?P\d+)/vote/$', 'polls.views.vote'),
)

 

 

 

 

 

你可能感兴趣的:(django)