有什么方法可以使 {% extends '...' %} 有条件?- 姜戈 [英] Any way to make {% extends '...' %} conditional? - Django

查看:38
本文介绍了有什么方法可以使 {% extends '...' %} 有条件?- 姜戈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 AJAX 和常规 HTTP 调用之间共享一个模板,唯一的区别是一个模板需要与 base.html html 一起提供,另一个不需要.

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 without.

有什么想法吗?

推荐答案

使用变量.

{% extends base_template %}

在您的视图中,将其设置为base.html",或者一个新的ajax.html"文件,它只提供块而不提供其他任何内容.

and in your view, set it to "base.html" in your view, or a new "ajax.html" file which just provides the block and nothing else.

这篇关于有什么方法可以使 {% extends '...' %} 有条件?- 姜戈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆