Is there a way to pass a variable to an 'extended' template in Django?

后端 未结 2 1236
星月不相逢
星月不相逢 2021-02-03 22:31

I want to add some flexibility to my layout template, but I can\'t find any way to do so.

I\'m looking for a way to extend my layout template with variable

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-03 23:01

    What you need is an include template tag. You can include a template in another template and render that with specific context.

    {% include 'layout.html' with sidebar=True sidebar_width=4 %}
    

    Check docs here: https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#include

提交回复
热议问题