开发者

Django generic view Template loading problem

开发者 https://www.devze.com 2023-03-14 05:44 出处:网络
I have the following view within an app called \'manager\': class AddObj(CreateView): model = Obj form_model = ObjForm

I have the following view within an app called 'manager':

class AddObj(CreateView):
    model = Obj
    form_model = ObjForm
    template_name = 'obj_add.html'
    success_url = 'obj'
    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(AddWar, self).dispatch(*args, **kwargs)

The template is located in: [project folder]/templates/manager/obj_add.html

If I specify template_name='manager/obj_add.html', it loads.

Also, since I'm using the django template dependency to create breadcrumbs, I want obj_add.html to extend from templates/manager/m_base.html, which extends from templates/structure.htm开发者_如何学Cl and adds a link to the breadcrumb block, and it loads if I call {% extends "manager/m_base.html" %}.

My question is: Doesn't django look for the templates recursively through the templates folder? Is it normal to have to specify the folder?


The reason you specify the app name when setting the template is twofold; there may be multiple templates of the same name, and you can have a project-level template override.

A third-party app will often have basic templates, though you may want to shuffle or override some of the blocks for your own purpose. For example:

App template:

[project]/manager/templates/manager/obj_add.html

Project override template:

[project]/templates/manager/obj_add.html

You can change the locations where templates will be loaded from.

0

精彩评论

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