在PyCharm Django项目中覆盖引导4种颜色-错误:Can';找不到要导入的样式表

在PyCharm Django项目中覆盖引导4种颜色-错误:Can';找不到要导入的样式表,django,npm,sass,bootstrap-4,pycharm,Django,Npm,Sass,Bootstrap 4,Pycharm,我正在尝试导入Bootstrap 4的Bootstrap.scss文件,如中所述。我的IDE是PyCharm。我的最终目标是通过导入引导和覆盖我想要的某些方面来覆盖引导4的颜色 问题是,我似乎无法将bootstrap.scss导入到项目中与node\u modules目录相关的custom.scss文件中 以下是我的项目结构: learnsass - learnsass <-- main Django project files (ex: settings.py) - myapp

我正在尝试导入Bootstrap 4的Bootstrap.scss文件,如中所述。我的IDE是PyCharm。我的最终目标是通过导入引导和覆盖我想要的某些方面来覆盖引导4的颜色

问题是,我似乎无法将
bootstrap.scss
导入到项目中与
node\u modules
目录相关的
custom.scss
文件中

以下是我的项目结构:

learnsass
  - learnsass <-- main Django project files (ex: settings.py)
  - myapp
    - static
      - myapp
        - css
          - custom.scss      <-- file I'm trying to import bootstrap from
            - custom.css         <-- automatically generated from file watcher
            - custom.css.map     <-- automatically generated from file watcher
    - ...
  - node_modules
    - bootstrap
      - dist
      - js
      - scss
        - bootstrap.scss     <-- the bootstrap scss I'm trying to import in custom.scss
        - ...
    - jquery
    - popper.js
  - static
  - templates
  - venv
  - db.sqlite3
  - manage.py
  - package.json
  - package-lock.json
带有输出消息的终端显示“错误:找不到要导入的样式表”

我已经尝试将
node\u modules
root设置为“Resource root”目录。我甚至尝试将其子目录设置为“资源根目录”或“源根目录”,但我尝试的组合都不起作用

在PyCharm中,我创建了一个文件监视程序,以便将SCS自动编译成custom.css。这些是我在那里的设置。也许我做错了什么

我确实找到了一个可行的解决方案(使用完全绝对路径) 我注意到,如果我在我的Windows机器上使用完整的绝对路径(如下所示),它实际上可以工作(custom.css文件是使用所有引导css生成的):


但我真的很想理解为什么不使用relative/sass/scss通用实践导入。我不是在寻找一个快速修复或任何黑客。加上,完全绝对URL导入是一种非常容易被破坏的事情。

我之所以出现
错误的原因是:找不到要导入的样式表。
是因为我没有意识到一件关键的事情-引导
@imports
来自
自定义。SCS
相对于
自定义中的位置。SCS
存在于您的项目

发件人:

注意:Bootstrap@import路径是相对于custom.scs的, 并且将根据您的项目环境而有所不同

执行导入操作时,需要定义从
custom.scss到引导.scss位置的路径

举几个例子:

# custom.scss lives inside static/project/scss/
@import "../../../node_modules/bootstrap/scss/bootstrap";

# custom.scss lives inside node_modules
@import "bootstrap/scss/bootstrap";

# custom.scss lives inside the root of the project
@import "node_modules/bootstrap/scss/bootstrap";
cmd.exe /D /C call C:\Users\Jarad\AppData\Roaming\npm\sass.cmd custom.scss:custom.css
Error: Can't find stylesheet to import.
  ╷
5 │ @import "~bootstrap/scss/bootstrap";
  │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  custom.scss 5:9  root stylesheet

Process finished with exit code 65
$theme-colors: (
  "primary": #cccccc,
  "danger": #840383,
);
@import "C:/Users/Jarad/Documents/PyCharm/learnsass/node_modules/bootstrap/scss/bootstrap.scss";
# custom.scss lives inside static/project/scss/
@import "../../../node_modules/bootstrap/scss/bootstrap";

# custom.scss lives inside node_modules
@import "bootstrap/scss/bootstrap";

# custom.scss lives inside the root of the project
@import "node_modules/bootstrap/scss/bootstrap";