1 urlpatterns = [2 url (r'^admin/', Admin.site.urls), 3 url (r'^votes/', include ("polls.urls ", namespace="polls")),4 ]
/myproject/urls.py
1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 4 " "5 @version:6 @author: Leo Yang7 @license: None8 @contact: [email protected]9 @site:Ten @software:P ycharm One @file: urls.py A @time (utc+8): 16/7/29-12:28 - " " - the fromDjango.conf.urlsImportURL - fromDjango.contribImportAdmin - from.Import views - +Urlpatterns = [ -URL (r'^admin/', Admin.site.urls), +URL (r'^index/', Views.index, Name="Index"), AURL (r'^detail/', Views.detail, Name="Detail"), atURL (r'^choice/', Views.choice, Name="Choice"), -URL (r'^result/', Views.result, Name="result"), -]
/projectname/polls/urls.pyy
1<! DOCTYPE html>2"en">34<meta charset="UTF-8">5<title>this isIndex page</title>67<body>8<li><a href="{% url ' polls:index '%}">{% URL'Polls:index'%}</a> </li>9<li><a href="{% url ' polls:detail '%}">{% URL'Polls:detail'%}</a> </li>Ten<li><a href="{% url ' polls:choice '%}">{% URL'Polls:detail'%}</a> </li> One<li><a href="{% url ' polls:result '%}">{% URL'Polls:result'%}</a> </li> A<li><a href="http://www.baidu.com">url:www.baidu.com</a></li> - -</body> the/projectname/polls/templates/index.html1 fromDjango.shortcutsImportRender2 fromDjango.httpImportHttpResponse3 fromDjango.shortcutsImportrender,get_object_or_404,get_list_or_4044 5 #Create your views here.6 7 8 defIndex (Request):9Ret_render = render (Request,"polls/index.html")Ten returnRet_render One returnHttpResponse ("The IS index page") A - - defDetail (Request): the returnHttpResponse ("This is detail page") - - - defChoice (Request): + returnHttpResponse ("This is choice page") - + A defresult (Request): at returnHttpResponse ("This is the result page")
/profectname/polls/views.pyDjango removing hardcoded URLs in template---Use variables to place URLs in variables {% url ' namespace:name '%}