开发者

Dynamically add to TEMPLATE_DIRS at runtime with a Django project

For a Django project I'm working on, I n开发者_Go百科eed 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('\\', '/'),
)

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

Any ideas?


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


I've done something like that, pls take a look here https://github.com/ASKBOT/askbot-devel/blob/master/askbot/skins/loaders.py

Besides the template loader you may need means to resolve media specific to your theme. It can be for example a template tag or a filter that takes some base url and adds theme prefix or something like that, also you could make that automatically keep track of media versions. That way that when you refresh .js or other file the client will have to load the latest version.


not sure if it's the same issue as my question theme switching, template and css file layout on a django site

subdirs of templates can be set as context var which is used as parameter for extend template tag

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜