django - 错误 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)
解决方案
推荐阅读
- ios - 颤振升级到 1.20.2 后无法为 IOS 构建
- testing - 使用 Testcafe 运行时 WebSocket 连接检查失败
- python - 如何通过拖放在 Tkinter 笔记本中重新排序选项卡
- javascript - 用道路制作褶裥动画
- html - 在 reactJS 中单击文本框的 div 外部时,将编辑的文本框值更改为原始传递的值
- apache-spark - PySpark:如何处理DataFrame的每一行
- android - 当被测试类而不是直接调用时,Mockito 的 `thenReturn` 返回 `null` 而不是 Pair(null."text")
- php - 通过 WooCommerce 中的 slug 获取产品属性标签名称
- javascript - 在 Monaco Editor 中禁用缩进指南
- botframework - microsoft botframework bot 如何在自适应卡片中提及用户?