django - Django图像标签不显示照片
问题描述
我想通过在 Django 模板文件“index.html”中使用 img src 标签来显示图像:
templates/
index.html
static/
img/
puzzle.png
将图像添加到静态后,我收集了静态并在页面顶部添加了:
{% load static %}
我的图像标签是:
<img src="{% static 'img/puzzle.png' %}">
但图像没有显示在我的页面上。我怎样才能解决这个问题?
解决方案
如下更改您的目录结构,
yourapp/
├── templates/
│ └── index.html
└── static/
└── yourapp
└── puzzle.png
然后在模板中,
{% load static %}
<img src="{% static 'yourapp/puzzle.png' %}">
参考
配置静态文件
推荐阅读
- python - 无法在 twitchio 中正确设置 initial_channels
- git - Git - 忽略对已在存储库中的文件的更改
- elastic-stack - 在自定义 Kibana 插件中使用 URL 参数
- matlab - 0 Hz 时的 Matlab FFT 峰值,无偏移
- c++ - 不知道我的高斯滤波器出了什么问题
- regex - 获取括号之间的多个值
- c++ - 仅在使用 snapcraft VM 时生成错误“ISO C++ 禁止零大小数组 'f_handle' [-Wpedantic]”
- jquery - 从 .js 文件中的静态加载图像时出现问题
- sql - 查找超过指定天数的任何人的最大连续缺勤天数
- sql - 了解使用 Presto/Athena 查询 ORC 时扫描的数据