Working With Multiple Settings

独自空忆成欢 提交于 2020-01-06 03:22:08

问题


I try to add multiple settings for my django project. Separate settings for devserver and production.

For this I removed my settings.py file and the new file structure would look like this:

mysite/
 |-- mysite/
 |    |-- __init__.py
 |    |-- settings/
 |    |    |-- __init__.py
 |    |    |-- base.py
 |    |    |-- development.py
 |    |    |-- production.py   
 |    |-- urls.py
 |    +-- wsgi.py
 +-- manage.py

I filled in base.py, development.py, production.py and replaced the path to the root of the project at base.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 

to ==>

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

And it working good at my local server when I start

python manage.py runserver --settings=mysite.settings.development

but when I do the same settings in production I get Internal server error. My server works for Nginx and Uwsgi.


回答1:


You have done this BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) correctly.

You need to do:

In settings/__init__.py file put the below codes.

from .production import *

try:
    from .local import *
except:
    pass

Now, run

python manage.py runserver

It will work fine.



来源:https://stackoverflow.com/questions/48976305/working-with-multiple-settings

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