创建模板目录
[[email protected] ~]# cd ~/ALU/alu02/blog/ [[email protected] 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:
[[email protected] 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)) [[email protected]-100-100-5-17 alu02]#
加载方法2:
[[email protected] alu02]# cat blog/views.pyfrom django.shortcuts import render_to_response def index(req): return render_to_response(‘index.html‘,{}) [[email protected]-100-100-5-17 alu02]#
测试界面
时间: 2024-10-24 07:16:41