Type the following code in the polls/urls.py file:
polls/urls.py
From Django.conf.urls import URL
From. Import views
Urlpatterns = [
URL (r ' ^$ ', Views.index, name= ' index '),
]
Next, let the main urlconf link to the Polls.urls module. Insert an include () in mysite/urls.py:
mysite/urls.py
From django.conf.urls import include, url
From Django.contrib Import admin
Urlpatterns = [
URL (r ' ^polls/', include (' Polls.urls ')),
URL (r ' ^admin/', include (Admin.site.urls)),
]
When someone requests a page of your site-such as "/polls/34/"-Django will load the Mysite.urls Python module because the root_urlconf setting specifies it. It looks for a variable named Urlpatterns and matches its regular expression sequentially. We use the Include () function to simply refer to other urlconfs. Note the end of the include () function's regular expression does not have a $ (end-of-string symbol) but a slash. whenever Django encounters an include (), it strips out the string that was previously matched in the URL, and then leaves the remaining string to the urlconf specified by the include () for further processing.
This article is from the "Big Barren Sutra" blog, please be sure to keep this source http://2892931976.blog.51cto.com/5396534/1739578
Django Learning Notes (iii)