我的项目文件夹是:
mrdoorbeen
manage.py
mr_doorbeen
setting.py
mrdoorbeen
migrations
templates
index.html
profile
profile.html
我想在我的 profile.html
文件中包含图像。
我在 profile.html
顶部使用 {% load staticfiles %}
并在图像源中使用此代码:
<img src="{% static "image/example.jpg" %}" alt="cant'load"/>
我在mr_doorbeen
中创建一个文件夹,并将其命名为static
,并在静态文件夹中创建一个image
文件夹,并将图像放在example.jpg
但它不起作用。 我的 静态
文件夹路径错误还是什么?
我应该把我的static
文件夹放在这个项目中
最佳答案
对于给定的目录结构,您可以将静态文件放在与文件 mr_doorbeen/settings.py
的目录相同的级别
mrdoorbeen
manage.py
mr_doorbeen
setting.py
mrdoorbeen
migrations
templates
index.html
profile
profile.html
static/
您可以将静态文件设置到上述位置,如下所示。
# Static files configurations.
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
关于python - 无法在我的 django 模板中加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42736773/