我有不屬于任何特定應(yīng)用的共享模板。這是我的項(xiàng)目樹:.├── 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在我的設(shè)置文件中,我有: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')]在我的基本模板.html,我試圖從 static/css/styles 調(diào)用樣式.css.css這樣:{% load static %}<link rel="stylesheet" type="text/css" href="{% static "css/styles.css" %}" />但服務(wù)器以未找到的響應(yīng):"GET /static/css/styles.css HTTP/1.1" 404我做錯(cuò)了什么?
Django:如何在共享模板中添加靜態(tài)文件?
拉丁的傳說(shuō)
2022-08-02 10:37:49