[英]How to use Settings.py file if it is in local directory
I have a Django project, let's say "project1". 我有一个Django项目,我们说“ project1”。 Typical folder structure for applications is:
应用程序的典型文件夹结构为:
/project1/
/project1/
/settings.py
/urls.py
/wsgi.py
/manage.py
Now I want to move this settings.py file into local directory. 现在,我想将此settings.py文件移动到本地目录中。 Then how to use this setting.py file in our project (What should i write in manage.py and wsgi.py for use of settings.py file from new moved local directory location)
然后如何在我们的项目中使用这个setting.py文件(我应该在manage.py和wsgi.py中写些什么,以便从新移动的本地目录位置使用settings.py文件)
You need to add your local directory into your Python path (don't forget to put a __init__.py
file in the local folder) and adapt your DJANGO_SETTINGS_MODULE
environment variable, which is defined in the manage.py
: 您需要将本地目录添加到Python路径中(不要忘记在本地文件夹中放置
__init__.py
文件),并修改在manage.py
定义的DJANGO_SETTINGS_MODULE
环境变量:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourproject.settings")
Be aware that it will take the first yourproject.settings
found in your Python Path, so it is not really a good idea to move it from the folder project. 请注意,它将需要在Python路径中找到的第一个
yourproject.settings
,因此将其从文件夹项目中移出并不是一个好主意。 You can also use the --settings
option to specify the file to use. 您也可以使用
--settings
选项指定要使用的文件。
python manage.py runserver --settings=yourproject.settings
Be careful, if you are doing this to avoid to commit the settings on a SVN/Git/Hg repository, it might be way easier to ignore the file in your CVS configuration, by ignoring settings.py
(and *.pyc
) 请注意,如果这样做是为了避免在SVN / Git / Hg存储库中提交设置,则可以通过忽略
settings.py
(和*.pyc
)来更轻松地忽略CVS配置中的文件。
you have to set DJANGO_SETTINGS_MODULE
environment variable in django.wsgi 您必须在django.wsgi中设置
DJANGO_SETTINGS_MODULE
环境变量
if you are using django with apache and mod_wsgi, have a look at https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/ 如果您将Django与apache和mod_wsgi一起使用,请访问https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.