Can't load image in my django template

萝らか妹 提交于 2019-12-08 03:54:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!