开发者

Django Loading Templates with Inheritance from Specific Directory

In our project, we have a bunch of different templates that clients to choose from (for their webstore). The file layout is something like this:

templates
    cart.html
    closed.html
    head.html
    standard
        bishop
        default
        indiana
        marley
        mocca
        nihilists
        raconteurs
        tripwire

Every subfolder of standard contains a few template files like base.html, browse.html and item.html. Browse and Item inherit from base.

What I want to do is render the browse template in a specific t开发者_如何学JAVAemplate folder (let's say templates/standard/bishop) isolated from any other global template path settings in my app. Is there a way to do that?

UPDATE: I'll try to be more clear. If I just render browse.html from the bishop subfolder it tries to extend base.html and it can't find it. I could alter the settings template path to include the bishop folder, but I'm looking for a way to make it work leaving that alone.


In your templates/standard/bishop/browse.html template you're doing the following:

{% extends "base.html" %}

This refers to templates/base.html and not templates/standard/bishop/base.html. By default Django will check your installed applications as well as the template directories that you specified under TEMPLATE_DIRS in settings.py.

This behavior is specified by TEMPLATE_LOADERS in settings.py:

  • http://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
  • http://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types

You might be able to get away with what you're trying to do by creating your own template loader, otherwise simply specify the actual path to base.html:

{% extends "standard/bishop/base.html" %}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜