本文介绍了在运行时通过Django项目动态添加到TEMPLATE_DIRS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我正在处理的Django项目,我需要能够允许用户指定TEMPLATE_DIRS中使用的路径.这是为了实现可选的主题".例如:

For a Django project I'm working on, I need to be able to allow the user to specify the path used in TEMPLATE_DIRS. This is to implement selectable "themes". For example:

TEMPLATE_DIRS = (
    os.path.join(WEBSITE_ROOT, 'templates', THEME_NAME).replace('\\', '/'),
    os.path.join(WEBSITE_ROOT, 'templates', 'default').replace('\\', '/'),
)

但是THEME_NAME变量应该通过站点管理来自数据库.

But the THEME_NAME variable should come from the database via the site administration.

有什么想法吗?

推荐答案

写一个模板加载器,您可以改为指向主题目录.

Write a template loader you can point at a theme directory instead.

这篇关于在运行时通过Django项目动态添加到TEMPLATE_DIRS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 12:47