【发布时间】:2016-02-06 00:58:00
【问题描述】:
我将上下文信息发送到视图的这一部分。有一个分页器,适用于第 1-3 页。但是转到第四页它有这个错误。
异常类型:ValueError
异常值:“图像”属性没有与之关联的文件。
django debug as 突出显示模板中的错误
模板渲染时出错
在模板/templates/marketplace/entry_list.html,第91行出错:
“图像”属性没有与之关联的文件。
<a href="{{ e.get_absolute_url }}" title="{{ e.title }}">
{% if e.picture.url %}
{% thumbnail e.picture "300x600" as thumb %}
<img src="{{ thumb.url }}" alt="{{ e.title }}" />
{% endthumbnail %}
{% endif %}
</a>
视图发送上下文信息部分如下
get_context_data(self, **kwargs):
if self.request.mobile:
self.template_name = 'mobile/buy_n_sell.html'
today = datetime.date.today()
context = super(EntryList, self).get_context_data(**kwargs)
context['category'] = self.category
try:
children = self.category.get_child_categories()
except:
children = None
context['child_category'] = children
context['area'] = self.area
return context
【问题讨论】:
-
尝试将 {% if e.picture.url %} 更改为 {% if e.picture %}。 “url”是一个只读属性,它在内部调用方法 _require_file() 来检查文件是否存在。因此,如果文件不存在,它将引发 ValueError
-
/templates/marketplace/entry_list.html的第 91 行是哪一行?
标签: django python-2.7 django-templates