【发布时间】:2020-09-18 04:28:08
【问题描述】:
试图将 sass 集成到我的 django3.1 项目中。我曾尝试使用其他方法(例如 Django-compressor)来实现 sass,但也无法让它在那里工作。因此,任何有关实现 sass 工作最终目标的建议都将不胜感激。
按照https://terencelucasyap.com/using-sass-django/ 上的步骤,我尝试实现 Django-sass-processor,但是当我转到主页时,它给了我错误Unable to locate file style.scss while rendering tag 'sass_src' in template app/index.html
Settings.py
INSTALLED_APPS = [
...
#SASS
'sass_processor',
]
...
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'sass_processor.finders.CssFinder',
]
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = '/static/'
#DJANGO SASS
SASS_PROCESSOR_ROOT = STATIC_ROOT
base.html
{% load sass_tags %}
{% load static %}
...
<link href="{% sass_src 'style.scss' %}" rel="stylesheet" type="text/css" />
该网站似乎在管理页面上正常工作。 我运行了 collectstatic 并且管理 CSS 与 style.scss 在同一个文件夹中,所以我认为它不是 STATIC_ROOT 的问题,但我不确定错误发生在哪里。
树
../ROOT/
├── db.sqlite3
├── manage.py
├── README.md
├── requirements.txt
├── static
│ ├── admin
│ └── style.scss
├── PROJECT
│ ├── asgi.py
│ ├── __init__.py
│ ├── __pycache__
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── APP
├── admin.py
├── apps.py
├── forms.py
├── __init__.py
├── migrations
├── models.py
├── __pycache__
├── templates
│ └── APP
│ ├── base.html
│ ├── cityFrom.html
│ └── index.html
├── tests.py
├── urls.py
└── views.py
我缺少什么导致 Django 无法找到该文件? 感谢您的任何建议!
【问题讨论】:
标签: django sass django-staticfiles