django - django {%url%} 用于 {%include%}
问题描述
当我尝试渲染此模板时:
{% include "mylistitem.html" with text="foo" btn_text="bar" href="{% url 'register' %}" %}
它会产生以下错误:
TemplateSyntaxError: 无法解析余数: '"{%' from '"{%'
在文档中,我发现无法嵌套表达式。我怎么能做到这一点?
解决方案
我不相信你可以嵌套模板标签。
您当前问题的解决方案是这样做:
{% url 'register' as register_url %}
{% include "mylistitem.html" with text="foo" btn_text="bar" href=register_url %}
这是一个重复的问题:Nested Django tags
推荐阅读
- google-places-api - 我已经在地图 fagment 上集成了 AutocompleteSupportFragment。当我点击地点搜索时。应用程序崩溃了
- c - 在C中的两个给定字符之间打印所有ASCII字符
- ocaml - OCaml - 为什么数组引用是默认的
- ios - 如何知道用户是否共享了我的应用程序?
- google-chrome - Aframe 激光控制不适用于 chrome canary 中的 WMR 耳机
- javascript - 离子/角度问题:尝试区分“[object Object]”时出错
- tensorflow.js - 错误:io_utils.ts:116 未捕获(承诺中) RangeError:Float32Array 的字节长度应为 4 的倍数
- r - 为什么矩阵到栅格显示旋转?
- python - 如何在 Django 的 ImageField 中保存用户输入 img
- visual-studio - 如何在 Visual Studio 中删除当前行周围的矩形?