繁体   English   中英

“图像”属性没有与之关联的文件 django

[英]The 'image' attribute has no file associated with it django

我正在做一个部署在 pythonanywhere.com 中的电子商务项目,出现了一些错误,如果有人能帮助我找出问题,我将不胜感激,因为我是一个基础学习者 TIA

我用 python 和 django 开发了一个在线书店应用程序,我有两个 MySQL 表用于类别和产品,在本地主机上运行时它工作得很好,但是在 pythonanywhere 中的部署只在图像字段中出现问题,也给出了 static 路径

错误在这里输入图像描述

在此处输入图像描述

需要在 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM