【问题标题】:django integrate htmls into templatesdjango 将 htmls 集成到模板中
【发布时间】: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


【解决方案1】:

您还需要将object_list 传递给profile.html

【讨论】:

    【解决方案2】:

    不太清楚你在问什么,但我怀疑custom template tag 可能是你想要的。

    【讨论】:

      猜你喜欢
      • 2013-09-15
      • 2018-03-23
      • 1970-01-01
      • 2019-01-21
      • 2019-03-31
      • 2017-03-27
      • 2014-06-21
      • 1970-01-01
      • 2016-06-17
      相关资源
      最近更新 更多