Any way to make {% extends '…' %} conditional? - Django

前端 未结 4 753
长发绾君心
长发绾君心 2020-11-27 04:21

I would like to share a template between AJAX and regualr HTTP calls, the only difference is that one template needs to be served with the base.html html, the other one with

4条回答
  •  抹茶落季
    2020-11-27 04:55

    The other answers require you to pass an additional context variable. But as long as you can access the request object, there is no need:

    {% extends request.is_ajax|yesno:"app/base_ajax.html,app/base.html" %}
    

    I found this to be much more convenient.

提交回复
热议问题