Django 根据子域使用不同的 settings.py 文件
Django 如何根据子域使用不同的settings.py 文件。
如果有不同的设置连接到不同的数据库,这些实用程序(“django-admin”、“python manage.py”)仍然可以使用吗?
How can Django use different settings.py file based on subdomains.
Can these utilities ("django-admin", "python manage.py") still be used if there were different settings connecting to different databases.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,您需要用设置覆盖两个维度:
这是我的建议:
universal_settings.py
- 您想要在任何地方继承的所有设置(所有计算机、所有域) )local_settings.py
- 每台计算机的设置(数据库设置、邮件服务器等)site_1.py
- 特定于您的某个域的设置site_2.py
- 特定于您的某个域的设置site_n.py
- 你会发现universal_settings.py 的底部应该包括:
这将根据需要覆盖通用设置中的任何内容。
同样,每个
site_1.py
、site_2.py
、site_n.py
设置文件应以以下内容开头:最后,您需要设置一个每个域的 apache(或 nginx 或其他)实例,并使用适当的
site_n.py
作为该服务器的设置文件这是最适合我的方法:)
ok you have two dimensions you need to cover with your settings:
Here is what I recommend:
universal_settings.py
- all the settings you want to inherit everywhere (all machines, all domains)local_settings.py
- settings on a per machine basis (database settings, mail server, etc)site_1.py
- settings that are specific to a one of your domainssite_2.py
- settings that are specific to a one of your domainssite_n.py
- you get the ideathe bottom of universal_settings.py should include:
This will override anything in the universal settings as necessary.
similarly, each of the
site_1.py
,site_2.py
,site_n.py
settings files should begin with:Finally you need to set up an apache (or nginx, or whatever) instance for each domain and use the appropriate
site_n.py
as the settings file for that serverThis is the method that works best for me :)