Python Django Template Usage process
I. Creation of the project
# django-admin.py Startproject csvt02
# CD csvt02
Second, create the application
# django-admin.py Startapp Blog
Third, add Access URL
# egrep-v "#|^$" urls.py
From django.conf.urls.defaults import patterns, include, url
Urlpatterns = Patterns ("',
URL (r ' ^index/$ ', ' Blog.views.index '),
URL (r ' ^index1/$ ', ' blog.views.index1 '),
URL (r ' ^index2/$ ', ' blog.views.index2 '),
)
Iv. Adding view Files
# Cat blog/views.py
From django.template import loader,context,template
From django.http import HttpResponse
From django.shortcuts import Render_to_response
def index (req):
t = loader.get_template (' index.html ') # import Template Object
c = Context ({' uname ': ' Loyu '}) # Create a Context object add data to a template render
html = T.render (c) # render the template
return HttpResponse (HTML)
def index1 (req):
t = Template ('
c = Context ({' uname ': ' Loyu '})
html = T.render (c)
return HttpResponse (HTML)
def index2 (req):
Return Render_to_response (' index.html ', {' uname ': ' Loyu '})
Five. Add template file
# Cat Blog/templates/index.html
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/>
<title>{{title}}</title>
<body>
</body>
Vi. Commencement of Project projects
# python manage.py runserver
This article is from "Meteor Yu" blog, please be sure to keep this source http://8789878.blog.51cto.com/8779878/1850745
Vi. Python Django Template usage process