Django:静态图片未加载

时间:2020-06-05 17:40:56

标签: python html django

我在将图像加载到Django Web应用程序时遇到问题。我已经使用了在线文档并尝试了在Stackoverflow上找到的人们的建议,但是我仍然没有运气来加载它。这是我所拥有的:

Settings.py:

STATIC_DIR =  os.path.join(BASE_DIR,'static')

INSTALLED_APPS = [
...
'django.contrib.staticfiles'
]

STATIC_URL = '/static/'
STATIC_ROOT = [STATIC_DIR,]

Urls.py:

from django.urls import path
from dir_app import views
from django.conf import settings
from django.conf.urls.static import static

app_name = 'dir_app'

urlpatterns=[
   path('', views.tradesmen, name='tradesmen'),
   path('register', views.register,name='register'),
   path('user_login', views.user_login,name='user_login')
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Index.html :(要点)

 <!DOCTYPE html>
 {% load static %}   
  <html>
   <head>
   </head>
   <body>
     <img src="{% static 'dir_app/tools.png' %}">
   </body>
  </html>

在此处存储图像:

location of IMAGE

1 个答案:

答案 0 :(得分:1)