开发者

django to use settings.py at a different location

开发者 https://www.devze.com 2022-12-14 06:16 出处:网络
I having issues getting Django to work with settings.py at different location I have a folder setting with test.py as copy of settings.py

I having issues getting Django to work with settings.py at different location

I have a folder setting with test.py as copy of settings.py

Folder laid out as

   models.py
   settings.py
   setting/
       test.py

this one works with default location

SetEnv DJANGO_SETTINGS_MODULE myproject.settings

python manage.py syncdb  --settings="myproject.settings"

this does not work when tring to use file in a subdirectory

SetEnv DJANG开发者_开发知识库O_SETTINGS_MODULE myproject.setting.test

python manage.py syncdb  --settings="myproject.setting.test"

Error

Error: Could not import settings 'myproject.setting.test' (Is it on sys.path? 
Does it have syntax errors?): No module named setting.test


I think your setting directory needs an __init__.py file so it is a valid Python package.


The more elegant way to split the settings for various kind of purpose is to replace the settings.py to settings as module and the original settings.py will be moved under settings, and rename to init.py like this,

   models.py
   settings/
           __init__.py
           test.py
0

精彩评论

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