首页 > 解决方案 > django内部的两个模板无法解析剩余部分

问题描述

Could not parse the remainder: '"' from '"'在这部分代码中遇到了错误:

{% include 'test.html' with pic_url="{% static 'picture.jpg' %}" %}

是否可以在 Django 模板中编写类似的内容?

标签: djangodjango-templates

解决方案


您不能像这样组合模板标签。

您可以做的是将一个模板标签的结果分配给变量。并非所有模板标签都可以,但static标签可以:

{% static 'blog-single.html' as some_variable %}
{% include 'test.html' with post_url=some_variable %}

推荐阅读