
[英]Django file not uploading: ValueError at / The 'image' attribute has no file associated with it
[英]The 'image' attribute has no file associated with it django
需要在 if 条件下检查图像是否为 None
<table>
<thead>
<tr>
<th>First Name</th>
<th>last Name</th>
<th>Mobile</th>
<th>E-Mail</th>
<th>City</th>
</tr>
</thead>
<tbody>
{% for i in data %}
<tr>
<td>
{% if i.image %} # need to check image is not None, this if check if image then render it else not
{{i.image.url}}
{% endif %}
</td>
<td>{{i.first_name}}</td>
<td>{{i.lastname}}</td>
<td>{{i.mobile}}</td>
<td>{{i.email}}</td>
<td>{{i.city}}</td>
</tr>
{% endfor %}
</tbody>
</table>
我发现问题是任何图像字段都没有,所以我从管理面板检查了所有记录并得到了一行图像属性为空。 所以在添加图像后它完美地工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.