社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  问与答

求助关于错误The 'image' attribute has no file associated with it.

唐1鸣-weibo • 8 年前 • 3589 次点击  

今天想要在post里加上 image=models.FileField(blank=True) enter image description here

然后进入admin,打开post,点开任意文章 enter image description here

见到此错误, enter image description here

谷歌了很久,说要把参数设为 blank=True,但我已经设置了。求论坛大神帮助

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/1496
 
3589 次点击  
文章 [ 4 ]  |  最新文章 8 年前
kinegratii
Reply   •   1 楼
kinegratii    8 年前

img标签src属性引用blank=True的ImageField需要判断图片是否存在

    {% if post.image %}
        <img src= '{{ post.image.url }}'/>
    {% else %}
        <p>暂无图片</p>
    {%endif %}
Ziv_Luther-weibo
Reply   •   2 楼
Ziv_Luther-weibo    8 年前

只有在访问image 字段的属性时,才会因为image字段为空,出现这个错误/

Ziv_Luther-weibo
Reply   •   3 楼
Ziv_Luther-weibo    8 年前

你应该把整个屏幕的错误提示, 截取下来。 显示模板33行有错误, 图片里 连33行是什么都看不到。

唐1鸣-weibo
Reply   •   4 楼
唐1鸣-weibo    8 年前

求大神介解惑