标签:
创建模板目录
[root@host-100-100-5-17 ~]# cd ~/ALU/alu02/blog/ [root@host-100-100-5-17 blog]# mkdir templates
通过bluefish创建html模板文件
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title></title> </head> <body> <h1>hello django</h1> </body> </html>
修改blog/views.py
加载方法1:
[root@host-100-100-5-17 alu02]# cat blog/views.pyfrom django.http import HttpResponse from django.template import loader, Context def index(req): t = loader.get_template(‘index.html‘) c = Context({}) return HttpResponse(t.render(c)) [root@host-100-100-5-17 alu02]#
加载方法2:
[root@host-100-100-5-17 alu02]# cat blog/views.pyfrom django.shortcuts import render_to_response def index(req): return render_to_response(‘index.html‘,{}) [root@host-100-100-5-17 alu02]#
测试界面
标签:
原文地址:http://www.cnblogs.com/onmyway227/p/5252145.html