** Until now, all applications have been set with one URLConf, but in reality it is easier to understand if you set each application. ** ** So, create a new URLConf for the polls app as follows.
# polls/urls.py
from django.conf.urls import patterns, include, url
urlpatterns = patterns('polls.views',
url(r'^$', 'index'),
url(r'^(?P<poll_id>\d+)/$', 'detail'),
url(r'^(?P<poll_id>\d+)/results/$', 'results'),
url(r'^(?P<poll_id>\d+)/vote/$', 'vote')
)
Previously, the first string in patterns was empty, but now polls.views has been added casually. By doing this, you can make it smarter than you used to write polls.views.detail or polls.views.results.
Then, link it to polls in the URLConf of the project body as follows.
mysite/urls.py ######
# mysite/urls.py
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))
)
This is OK.
Recommended Posts