无法在Django中导入设置 [英] Cannot import settings in Django
问题描述
我需要使用py.test测试我的Django应用.因此,我需要告诉py.test是Django的设置模块.我用于py.test的命令是:〜/GitHub/django-training $ py.test --ds = training.settings
I need to test my Django app with py.test. Hence, I need to tell py.test which is Django's settings module. The command I use for py.test is: ~/GitHub/django-training$ py.test --ds=training.settings
不幸的是,我收到此错误: ERROR:无法导入设置"training.settings"(在sys.path上吗?):没有名为training.settings的模块
Unfortunately, I get this error: ERROR: Could not import settings 'training.settings' (Is it on sys.path?): No module named training.settings
看起来很奇怪,因为我的文件夹结构如下:
Is looks very odd, because my folder structure looks like this:
django-training
training
settings.py
和我的 sys.path
在第一个位置上包含/home/user/GitHub/django-training
条目.
and my sys.path
contains the /home/user/GitHub/django-training
entry on the first position.
现在,为什么我不能使用该设置文件?
Now, why can't I use that settings file?
推荐答案
培训目录可能实际上不在sys.path上.通常的方法是在virtualenv中运行,并在 django-training
目录中运行 pip install -e
,前提是它具有 setup.py
.但是适合您的开发工作流程的任何其他方式都可以.
The training directory is probably really not on sys.path. A usual approach is to run in a virtualenv and run pip install -e .
in the django-training
directory, assuming it has a setup.py
. But any other means which fits with your development workflow is fine.
这篇关于无法在Django中导入设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!