django html render_to_response

#coding=utf-8
from django.shortcuts import render
from blog.models import BlogPost
from django.shortcuts import render_to_response

# Create your views here.
def index(request):
	blog_list = BlogPost.objects.all()
	return render_to_response('index.html',{'blog_list':blog_list})
{% for post in blog_list %}
	<h2>{{ post.title }}</h2>
	<p>{{ post.timestamp }}</p>
	<p>{{ post.body }}</p>
{% endfor%}

 

for post in blog_list 中的blog_list一定要和引号中的内容相同'blog_list'

posted @ 2017-05-09 16:39  liuzhipenglove  阅读(362)  评论(0编辑  收藏  举报