django 模板 - 在包含的模板中使用 block.super 失败(例外)
这个想法是在一个页面上有多个小部件,并包含此“小部件”所需的所有 js 和 css 文件(通过这种方式管理文件很容易)。重复的文件不是问题。 每个小部件的模板都由 {%include%} 包含到页面中 从小部件的模板内部,我尝试将内容添加到父块:
PARENT:
{%block js%}
{%endblock%}
WIDGET
{%block js%}
{{block.super}}
///my widget spectyfic JS
{%end block%}
这给出了 {{block.super}} 错误:渲染时捕获 AttributeError: 'BlockNode' 对象没有属性 'context'
我不知道我还能如何扩展块...似乎在 django 中是不可能的...有什么想法吗? 定义多个块是行不通的,因为我们不知道每个页面上有多少个具有什么名称的不同小部件......(这不是 nemplate 担心的)
the idea is to to have multiple widgets on a page and include all js and css files needed form this 'widgets' (it's easy to manage files this way). Duplicated files is not a problem.
Every widget's template is included into a page by {%include%}
From inside widget's template I'm trying to add content to parent's block:
PARENT:
{%block js%}
{%endblock%}
WIDGET
{%block js%}
{{block.super}}
///my widget spectyfic JS
{%end block%}
this is giving an error with {{block.super}}: Caught AttributeError while rendering: 'BlockNode' object has no attribute 'context'
I'm not sure how else can I extend block... Seems it's impossible in django... any ideas?
Defining multiple blocks will not work as we don't know how many different widgets with what names will we have on each page... (and it's not a nemplate's worry)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自文档:
如果您希望 block.super 工作,那么您需要使用
扩展
。From the docs:
If you want
block.super
to work then you need to useextends
instead.我知道有点晚了,但我可能有一些解决方案。使用 django-sekizai 您可以将 js 和 css 加载到一处。看看 http://django-sekizai.readthedocs.org/en/latest/
I know it a bit too late but I may have some solution. Using django-sekizai you can load js and css into one place. Take a look at http://django-sekizai.readthedocs.org/en/latest/