【发布时间】:2014-07-29 05:25:41
【问题描述】:
我正在尝试向模板添加一些图片库,但页面上图库的位置需要由用户定义。有时它会在文本的顶部,有时在末尾,有时在页面文本的中间。在文本字段中,用户将添加这一行#foto,并根据我需要渲染画廊的那一行的位置。例如:
some paragraph written by user in the text field...
#foto
some another paragraph written by user ...
现在最简单的方法是在视图中将#foto 替换为包含标签。比如:
foto = "{% include 'includes/gallery.html' %}"
xx = "#foto"
post.text = post.text.replace(xx, foto)
但是这个例子不起作用,因为包含标签不能以这种方式调用。它呈现为纯文本 {% include 'includes/gallery.html' %}。可以做些什么来在 #foto 文本的位置上按预期呈现包含标记。
【问题讨论】:
标签: django django-templates django-views django-filter