问题
My project folders is :
mrdoorbeen
manage.py
mr_doorbeen
setting.py
mrdoorbeen
migrations
templates
index.html
profile
profile.html
I want to include a image in my profile.html file.
i use {% load staticfiles %} in top of the profile.htmland use this code at image source :
<img src="{% static "image/example.jpg" %}" alt="cant'load"/>
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
回答1:
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')
回答2:
The problem is with your settings file where you need to define STATIC_URL. Just follow the description in Django's documentation.
来源:https://stackoverflow.com/questions/42736773/cant-load-image-in-my-django-template