注意:配置项是个元祖,如果只有一项,别忘了在元素后面加逗号
settings:
STATICFILES_DIRS = (os.path.join(BASE_DIR,'static'),)
urls:
path('test_static', views.test_static)
views:
def test_static(request):return render(request,'test_statuic.html')
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>测试静态文件</title>
</head>
<body>
<img src="http://127.0.0.1:8000/static/image/img.jpeg">
<img src="/static/image/img.jpeg">
{% load static %}
<img src="{% static 'image/img.jpeg' %}">
</body>
</html>