开发者

Django: What is `sys.path` supposed to be?

开发者 https://www.devze.com 2023-01-16 04:43 出处:网络
When developing a Django application, what is sys.path supposed to contain? The directory which conta开发者_StackOverflow中文版ins the project, or the directory of the project, or both?sys.path should

When developing a Django application, what is sys.path supposed to contain? The directory which conta开发者_StackOverflow中文版ins the project, or the directory of the project, or both?


sys.path should and will have the directory of the project. Depending on what your setup is, it may also contain the directory which contains the project.

However, if the motivation behind this question is to ensure that certain files can be found, then you should note that sys.path is just like a normal list and can be appended to. Therefore, you can add a new location to sys.path like so:

sys.path.append('/home/USER/some/directory/')

where your files can be found.

Hope this helps


As far as I know, it's just a matter of personal taste. I go with the directory which contains the project, but that's just my preference.

0

精彩评论

暂无评论...
验证码 换一张
取 消