0
我有發送到這部分視圖的上下文信息。有一個paginator並適用於第1-3頁。但是在第四頁中有這個錯誤。Django模板ValueError'圖像'屬性沒有關聯的文件
異常類型:ValueError異常
異常值: '圖像' 屬性沒有與之相關聯的文件。
模板中的錯誤是由django的調試模板渲染
在模板/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
嘗試{如果e.picture.url%}更改爲{%如果e.picture%}。 「url」是一個只讀屬性,它在內部調用方法_require_file()來檢查文件是否存在。所以如果文件不存在,它會引起ValueError – GreyZmeem
這是'/ templates/marketplace/entry_list.html'的第91行嗎? –
[Django'image'屬性沒有與之關聯的文件]的可能重複(http://stackoverflow.com/questions/15322391/django-the-image-attribute-has-no-file-associated-with-it ) –