【发布时间】:2021-01-23 16:16:46
【问题描述】:
我正在使用 Django 教程做 Tango。我正在使用 Django 版本 3.1.1。我能够让我的图像加载到本地链接“http://127.0.0.1:8000/static/images/rango.jpg”
我没有让它加载到 index.html 代码是
<!DOCTYPE html>
{% load static %}
<html>
<head>
<title> Rango</title>
</head>
<body>
<h1>Rango says...</h1>
<div>
hey there partner! <br />
<strong>{{ boldmessage }} </strong><br />
</div>
<div>
<a href="/rango/about/">About</a><br />
<img src="{% static
'images/rango.jpg' %}"
alt="Picture of Rango" />
</div>
</body>
</html>
我确实尝试删除 html 中的“alt=”,但没有奏效。
我不认为问题出在我的 settings.py 上,但无论如何我都会分享 settings.py 的某些部分。
TEMPLATE_DIR = os.path.join(BASE_DIR,'templates') # this is the file path for templates
STATIC_DIR = os.path.join(BASE_DIR,'static') # this is the file path for static
STATICFILES_DIRS = [STATIC_DIR,]
...
#At the very bottom...
STATIC_URL = '/static/'
【问题讨论】:
-
-
尝试添加
STATIC_ROOT = STATIC_DIR -
ViLuWi:当我添加此
STATIC_ROOT = STATIC_DIR时,出现以下错误。 ERRORS: ?: (staticfiles.E002) STATICFILES_DIRS 设置不应包含 STATIC_ROOT 设置。 Eric Martin:我尝试了您的建议,但结果没有任何变化。