【发布时间】:2011-02-23 10:13:45
【问题描述】:
我有一个 django“模板”问题
如果我在views.py中有:
def cv(request):
if request.user.is_authenticated():
cv = OpenCv.objects.filter(created_by=request.user)
return render_to_response('cv/cv.html', {
'object_list': cv,
},
context_instance=RequestContext(request))
在 cv.html 中类似:
{% for object in object_list %}
<li>
First Name {{ object.first_name }} <br />
Last Name {{ object.last_name }} <br />
Url {{object.url}} <br />
Picture {{object.picture}} <br />
Bio {{object.bio}} <br />
Date of birth {{object.date_birth}} <br />
{% endfor %}
但我希望此内容也出现在 profile.html 页面上,我该怎么做?
profile.html 中的简单 {% include "cv/cv.html" %} 不起作用。
此外,除了像上面那样显式写入所有对象之外,还有另一种“解析对象列表”的方法吗?
提前致谢!
【问题讨论】:
-
你是否也在views.py的profile方法中发送了object_list?
-
不应该是:{% include "cv/cv.html" %} ??
-
我已经在 cv 应用程序的 views.py 中发送了 object_list,(见上文)我应该也将它发送到其他地方吗?是的,路径是正确的,我刚刚编辑了
-
是的,看Ignacio的回答,在profile view中渲染profile.html时需要在context中传递object_list。
标签: html django templates include