django 는 urlconf 에서 include 를 사용 합 니 다.

3173 단어 djangourlconf
루트 파일 urls.py
#coding=utf-8

"""django_book URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.8/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Add an import:  from blog import urls as blog_urls
    2. Add a URL to urlpatterns:  url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import include, url
from django.contrib import admin
from django.conf.urls import patterns

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

	#            patterns     
    #url(r'^books/$', "books.views.book_route", name="books_book"),
    #url(r'^books/(?P.+)/$', "books.views.book_detail", name="books_detail"),

    #url(r'^contactus/$', "django_forms.views.contactus", name="django_form_contactus"),
    #url(r'^contactus/thanks/', "django_forms.views.thanks", name="django_form_thanks"),

	#  include   ,include         username     
	#  include     ,      
	url(r'^(?P[a-zA-Z0-9]+)/blog/', include('advanced_views.urls')),
]

#  pattern   ,  view   
urlpatterns += patterns("books.views",
		url(r'^books/$', "book_route", name="books_book"),
		url(r'^books/(?P.+)/$', "book_detail", name="books_detail"),
)

#django_forms views
urlpatterns += patterns("django_forms.views",
		url(r'^contactus/$', "contactus", name="django_form_contactus"),
		url(r'^contactus/thanks/', "thanks", name="django_form_thanks", kwargs={"template_name":"django_forms/thanks.html"}),
)

advanced_views.urls.py
#coding=utf-8

from django.conf.urls import patterns, url
urlpatterns = patterns("advanced_views.views",
		url(r'^$', "index", name="advanced_views_index"),
		url(r'^articles$', "articles", name="advanced_views_articles"),
		)

advanced_views.views.py
#coding=utf-8

from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
#       username      unicode ,         
#              unicode   
def index(request, username):
	#    : unicode               (utf-8)
	return HttpResponse("

Urlconf include :username=%s

" % (username.encode("utf-8"),)) # : unicode #return HttpResponse(u"

Urlconf include :username=%s

" % (username,)) # : username , utf-8 unicode #return HttpResponse("

Urlconf include :username=%s

" % (username,))

좋은 웹페이지 즐겨찾기