无法加载我的django模板中的图像
我的项目文件夹是:
mrdoorbeen
manage.py
mr_doorbeen
setting.py
mrdoorbeen
migrations
templates
index.html
profile
profile.html
我想在我的 profile.html
文件中加入图片。
i在 profile.html
的顶部使用 {%load staticfiles%}
,并在图像上使用此代码来源:
I want to include a image in my profile.html
file.
i use {% load staticfiles %}
in top of the profile.html
and use this code at image source :
<img src="{% static "image/example.jpg" %}" alt="cant'load"/>
我在一个 mr_doorbeen
并将其称为 static
,并在静态文件夹中创建一个图像
文件夹和图像,我把一个示例.jpg
但它不工作。 我的 static
文件夹路径错误或什么?
我应该在哪里放置我的静态
文件夹
and i make a folder in a mr_doorbeen
and call it static
and in static folder make a image
folder and image i put a example.jpg
but it doesn't work . my static
folder path is wrong or what?
where should i put my static
folder in this project
对于给定的目录结构,您可以将静态文件放在与文件目录相同的级别上, mr_doorbeen / settings.py
For the given directory structure, You can put your static files on same level as of the directory with file, mr_doorbeen/settings.py
mrdoorbeen
manage.py
mr_doorbeen
setting.py
mrdoorbeen
migrations
templates
index.html
profile
profile.html
static/
你可以将静态文件设置为所述位置,如下所示。
You can set the static files to the said location as follows.
# Static files configurations.
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')