基本上,我有一个冒号分隔的变量传递到我的模板,我想循环显示每个单独的元素.
我希望能够提取每个名称,然后在我的模板中对它们执行逻辑.
如果我可以使用python,我会做类似的事情(注意:file_type是我模板中的变量):
file_type = "PDF:DOC:XLS"
for tipe in file_type.split(":"):
if tipe == "PDF":
print "<img src='pdf'/>"
elif tipe == "DOC":
print "<img src='doc'/>"
elif tipe == "XLS":
print "<img src='xls'/>"
else:
print "<img src='unrecognized'/>"
Run Code Online (Sandbox Code Playgroud)
基本上,django-templates中是否存在拆分功能,或者有没有人想出一个狡猾的方法来做到这一点?我找不到任何东西.谢谢!