如何为网站框架django设置多个settings.py? [英] How to set multiple settings.py for sites framework django?

查看:82
本文介绍了如何为网站框架django设置多个settings.py?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在尝试建立具有相同基础的多个网站.浏览时,我知道Django拥有我可以使用的Sites框架.

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

我没有获得如何使用网站ID设置多个settings.py文件的信息.有任何想法吗?

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

先谢谢您了:)

推荐答案

要从同一个Django实例提供多个站点,则不需要多个settings.py文件.

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

一种简单的方法是忽略Sites框架中的 SITE_ID 设置.然后包括网站框架中间件:

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'

这会在每次请求时自动将 request 对象传递给 Site.objects.get_current().它还允许您的Django应用程序通过 request.site 检测当前站点.

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.

您需要确保使用NGINX或apache实例设置多个虚拟主机,以将流量从每个站点路由到您的服务器.

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.

这篇关于如何为网站框架django设置多个settings.py?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆