如何优化我的代码?
这是我的视图和模板示例:
意见:
def index(request):
recomended = MyPost.objects.filter(recomented=True).order_by('add_date')
posts = MyPost.objects.all()[:9]
return render_to_response('main.html',{'recomended': recomended, 'posts':posts}, context_instance=RequestContext(request))
main.html
<h1>Website</h1>
{% for r in recomended %}
{{ r.title }}
{{ r.url }}
{% endfor %}
{% for p in posts %}
{{ p.title }}
{{ p.url }}
{% endfor %}