我将静态文件存储在项目根目录中,但是无法将其加载到浏览器中。
STATIC_DIR = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIR = [
STATIC_DIR,
]
<!DOCTYPE html>
{% load static %}
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Index</title>
</head>
<body>
<h1>{{temp}}</h1>
<h2><a href="#">Click here</a> to veiw user details</h2>
<img src="{% static "user/images/smile.png"%}" alt="oh oh didn't show"/>
</body>
</html>
答案 0 :(得分:0)
在文件urls.py
中添加静态网址。
urlpatterns = [
path('admin/', admin.site.urls),
...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)