.
âââ root_app
â âââ asgi.py
â âââ forms.py
â âââ __init__.py
â âââ __pycache__
â âââ settings.py
â âââ urls.py
â âââ views.py
â âââ wsgi.py
âââ db.sqlite3
âââ another_app
â âââ admin.py
â âââ api_services.py
â âââ apps.py
â âââ __init__.py
â âââ migrations
â âââ models.py
â âââ __pycache__
â âââ templates
â âââ tests.py
â âââ urls.py
â âââ utils.py
â âââ views.py
âââ manage.py
âââ Pipfile
âââ Pipfile.lock
âââ README.md
âââ requirements.txt
âââ static
â âââ css
â âââ styles.css
âââ templates
âââ base.html
âââ home.html
在我的设置文件中,我有:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
INSTALLED_APPS = [
...
...
'django.contrib.staticfiles',
]
STATIC_URL = '/static/'
STATIC_DIR = [os.path.join(BASE_DIR, 'static')]
在base.html模板中,我试图通过以下方式调用static/css/styles.css中的styles.css:
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static "css/styles.css" %}" />
但服务器以“未找到”响应:
"GET /static/css/styles.css HTTP/1.1" 404
我做错什么了?