[root@iZ28cumdzmgZ muahao02]# vim blog/templates/index.html
    





        
         muahao02


hello muahao02



[root@iZ28cumdzmgZ muahao02]# vim blog/views.py



from django.template import loader,Context,Template
from django.http import HttpResponse

方式1:
def index(req):
        t = loader.get_template('index.html')  #通过loader对象将index.html模板加载成t变量
        c = Context({'uname':'Alen'})    #通过Context对象将内容,赋值给变量c
        html = t.render(c)    #通过render方法,将内容渲染给模板
        return HttpResponse(html)   #通过HttpResponse对象进行返回

        
方式2:
注意:在使用第2种方式的时候,需要from django.template import Template
def index1(req):
        t = Template('

hello `uname`

')         c = Context({'uname':'Jack'})         return HttpResponse(t.render(c))



[root@iZ28cumdzmgZ muahao02]# vim muahao02/urls.py

from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'muahao02.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^index/$','blog.views.index'),
    url(r'^index1/$','blog.views.index1')