Cannot import settings in Django

烂漫一生 提交于 2019-12-13 02:18:53

问题


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

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

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?


回答1:


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.



来源:https://stackoverflow.com/questions/19638858/cannot-import-settings-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!