How to set multiple settings.py for sites framework django?

旧时模样 提交于 2020-01-07 03:00:36

问题


Am trying to set up multiple website with same base. While browsing, came to know Django has Sites framework which I could use.

I didnt get how to set multiple settings.py file with site id. Any ideas anyone?

Thanks in advance :)


回答1:


you can have multiple setting file for example develop.py and production.py steps 1. create a settings folder inside the project 2. Add all of the settings file to that folder 3 while running server

./manage.py runserver --settings=project_name.settings.required_settingfile

eg: ./manage.py runserver --settings=myproject.settings.develop




回答2:


To serve multiple sites from the same Django instance you do not need multilple settings.py files.

A simple method is to omit the SITE_ID setting from the Sites framework. Then include the Sites framework middleware:

'django.contrib.sites.middleware.CurrentSiteMiddleware'

This automatically passes a request object to Site.objects.get_current() on every request. It also allows your Django application to detect the current site via request.site.

You would need to make sure to setup multilple virtual hosts using your NGINX or apache instance to route traffic from each site to your server.



来源:https://stackoverflow.com/questions/40648557/how-to-set-multiple-settings-py-for-sites-framework-django

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