如何在 django 模板中连接字符串? [英] How to concatenate strings in django templates?
本文介绍了如何在 django 模板中连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 Django 模板标签中连接一个字符串,例如:
I want to concatenate a string in a Django template tag, like:
{% extend shop/shop_name/base.html %}
这里 shop_name
是我的变量,我想将它与路径的其余部分连接起来.
Here shop_name
is my variable and I want to concatenate this with rest of path.
假设我有 shop_name=example.com
并且我想要结果扩展 shop/example.com/base.html
.
Suppose I have shop_name=example.com
and I want result to extend shop/example.com/base.html
.
推荐答案
与:
{% with "shop/"|add:shop_name|add:"/base.html" as template %}
{% include template %}
{% endwith %}
这篇关于如何在 django 模板中连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文