[英]How to make Django support multiple domains with one settings.py?
We want one Django
instance to serve different domains. 我们希望一个
Django
实例可以服务于不同的域。 The only difference between them is different templates, all the rest is the same. 它们之间的唯一区别是模板不同,其余所有模板都相同。 So we tried to just modify TEMPLATES.DIRS in a
middleware
. 因此,我们试图在
middleware
修改TEMPLATES.DIRS 。 But Django templates loader ignores all the changes in TEMPLATES.DIRS made after settings.py
is loaded. 但是Django模板加载器会忽略
settings.py
加载后对TEMPLATES.DIRS所做的所有更改。
Is there more or less standard Django
Way to support different TEMPLATES.DIRS for different domains with just one settings.py
? 是否有或多或少的标准
Django
方式通过一个settings.py
为不同的域支持不同的TEMPLATES.DIRS ?
To solve your problem use a template variable, both extend
and include
support variables. 要解决您的问题,请使用模板变量,同时
extend
和include
支持变量。 Just omit the quatation marks: 只需省略引号即可:
{% extends "base.html" %}
becomes 变成
{% extends string_variable_with_file_name %}
Of cause you have to set that variable to the right filename in your context. 原因是您必须在上下文中将该变量设置为正确的文件名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.