注意:配置项是个元祖,如果只有一项,别忘了在元素后面加逗号
settings:
python
STATICFILES_DIRS = (os.path.join(BASE_DIR,'static'),)
urls:
python
path('test_static', views.test_static)
views:
python
def test_static(request):
return render(request,'test_statuic.html')
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>