Django图像标签不显示照片

问题描述 投票:2回答:1

我想通过在Django模板文件“index.html”中使用img src标记来显示图像:

templates/
    index.html
static/ 
    img/
       puzzle.png

将图像添加到静态后我收集静态并在页面顶部我包括:

{% load static %}

我的图片标签是:

<img src="{% static 'img/puzzle.png' %}">

但图像没有显示在我的页面上。我怎样才能解决这个问题?

django image static django-views src
1个回答
0
投票

更改目录结构如下,

yourapp/
├── templates/
│   └── index.html
└── static/
    └── yourapp
        └── puzzle.png

然后在模板中

{% load static %}
<img src="{% static 'yourapp/puzzle.png' %}">

参考 Configuring static files

© www.soinside.com 2019 - 2024. All rights reserved.