使用django和html显示图像

时间:2017-10-23 18:46:08

标签: html django

我不确定我做错了什么,但我的图片不会显示

HTML:

 {% load static %}
 <img src="{% static 'images/IMG_0096.JPG' %}" alt="Mountain View"/>

settings.py:

 STATIC_URL = '/static/'

 STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static"), )

由于

1 个答案:

答案 0 :(得分:0)

STATIC_ROOT设置添加到settings.py以查看静态文件

`STATIC_ROOT = os.path.join(BASE_DIR, "static")

如果您在开发环境中,请在urls.py

中添加此设置
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)