首页 > 解决方案 > 错误 Django 'imagem' 属性没有与之关联的文件

问题描述

有人可以帮我理解为什么标签:

{{ post.author.imagem }} 

返回我 --> perfil/imagem1.jpg

和标签

{{ post.author.imagem.url }} 

返回一个错误:“imagem”属性没有与之关联的文件。

html

{% if post.author.imagem %}
<img src="{{ post.author.imagem.url }}" alt="{{ post.author.first_name }}" 
class="rounded-circle" style="width: 50px; height: 50px; margin-right: 20px;">
{% endif %}
class Post(models.Model):
author = models.ForeignKey(get_user_model(), verbose_name='author', on_delete=models.CASCADE , null=True, blank=True)

标签: djangodjango-modelsdjango-views

解决方案


推荐阅读