简体   繁体   English

如何在 Django 中检查 BASE_DIR?

[英]How to check BASE_DIR in django?

I was running into a lot of file not found for webpack in my static folder, and I later realized that for some reason this particular project (which I'm using docker with) keeps trying to check another project folder's static folder for the files I would want.我在我的静态文件夹中遇到了很多找不到 webpack 的文件,后来我意识到由于某种原因,这个特定的项目(我正在使用 docker)一直试图检查另一个项目文件夹的静态文件夹中的文件我会想要。 I'm not sure where this could've gone wrong other than the base_dir, but I never changed that setting.我不确定除了 base_dir 之外哪里可能出错,但我从未更改过该设置。 There was a while I was going between the projects and trying to run each one (the other project is basically the same thing but not on docker), was that possibly what's confusing the program?有一段时间我在项目之间切换并试图运行每个项目(另一个项目基本上是相同的,但不是在 docker 上),这可能是程序混淆的原因吗? How can I solve it?我该如何解决?

BASE_DIR 写在 settings.py 文件中,您可以通过导入来使用它。

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

os.path.join(BASE_DIR,filename)

you can find this code in setting.py file in Django also, you can import that also您也可以在 Django 的 setting.py 文件中找到此代码,您也可以导入该代码

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

STATIC_ROOT=os.path.join(BASE_DIR,'staticfiles/')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM