Django Learning Notes (iii)

Source: Internet
Author: User


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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.