Vi. Python Django Template usage process

Source: Internet
Author: User

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

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.