Django 如何在夹层多租户中启用每个站点的模板

Django 如何在夹层多租户中启用每个站点的模板,django,mezzanine,multi-tenant,Django,Mezzanine,Multi Tenant,我们正在将业务扩展到欧洲,我正在使用Mezzanine的多租户功能,在同一Django安装上托管该网站的美国和欧盟版本。我们在每个站点上都有一个/locations页面,我希望根据站点ID使用不同的模板 我遵循了Mezzanine的稀疏文档,并将以下内容添加到settings.py HOST_THEMES = [ ('domain.com', 'domain_app'), ('domain.eu', 'domain_eu') ] def host_theme_path(req

我们正在将业务扩展到欧洲,我正在使用Mezzanine的多租户功能,在同一Django安装上托管该网站的美国和欧盟版本。我们在每个站点上都有一个
/locations
页面,我希望根据
站点ID
使用不同的模板

我遵循了Mezzanine的稀疏文档,并将以下内容添加到
settings.py

HOST_THEMES = [
    ('domain.com', 'domain_app'), 
    ('domain.eu', 'domain_eu')
]
def host_theme_path(request):
    """
    Returns the directory of the theme associated with the given host.
    """
    for (host, theme) in settings.HOST_THEMES:
        if host.lower() == request.get_host().split(":")[0].lower():
我在基本主题之后添加了
domain\u eu
INSTALLED\u APPS
,并使用
python manage.py startap domain\u eu
生成目录,并手动创建
domain\u eu/templates/pages/locations.html
文件

然后我复制了位置页面并将其分配到EU站点

页面仍然使用位于基本主题
domain\u app/templates/pages/locations.html中的位置模板呈现

我已确认请求中设置了正确的
站点ID


如何根据当前的
站点ID
在相应的主题/应用程序目录中使用模板呈现页面?

在深入了解Mezzanine的代码后,我找到了我的eu主题模板不呈现的原因。在
mezzanine/utils/sites.py

HOST_THEMES = [
    ('domain.com', 'domain_app'), 
    ('domain.eu', 'domain_eu')
]
def host_theme_path(request):
    """
    Returns the directory of the theme associated with the given host.
    """
    for (host, theme) in settings.HOST_THEMES:
        if host.lower() == request.get_host().split(":")[0].lower():
当我记录
request.get\u host()
的结果时,我很快意识到了这个问题,因为它是
localhost
,显然与任何
host\u主题
域都不匹配

我假设Mezzanine会按照使用会话变量
site\u id
,但显然不会沿着这个特定的模板呈现代码路径

因此,解决方案只需使用以下内容编辑我的
/etc/hosts
文件:

127.0.0.1 domain.eu
现在,当我访问
domain.eu/locations
时,它从正确的主题目录(在本地开发环境中)呈现模板