修改blog/templates/index.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}}</title> </head> <body> {% if book_list%} {% for book in book_list %} <h1>{{book}}</h1> {% endfor %} {% else %} <h1>There is no book</h1> {% endif %} </body> </html>
修改blog/views.py
from django.shortcuts import render_to_response def index(req): book_list = [‘python‘, ‘django‘, ‘mysql‘] return render_to_response(‘index.html‘,{‘title‘:‘my page‘, ‘book_list‘:book_list})
测试界面
原文:http://www.cnblogs.com/onmyway227/p/5252302.html