[英]How to loop over custom plugin data on the template in django cms 3.5.3
[英]simple loop in rendered template django cms plugin
我想循环渲染模板中从数据库中获取的数据。 使用cms插件。 我没有在html模板中循环数据的问题。 但是,如果我使用CMSPlugin在占位符中插入新应用,则不会显示任何内容。
如果我运行url localhost:port / test.html。我得到了我想要的输入。 但是渲染的模板不会循环数据。
{% for post in posts %}
{{ post.firstoption }}
{% endfor %}
如果我使用下面的代码,则渲染的模板中没有任何显示。 值在呈现的模板中传递。 因为,如果我尝试{{instance.firstoption}},我会获得模板中显示的价值。 问题是我无法使用标签实例循环数据。
{% for post in instance.posts %}
{{ post.firstoption }}
{% endfor %}
我还尝试了{% for post in instance.posts_set.all %}
{% for post in instance.posts.all %}
和{% for post in instance.posts.all %}
cms_plugins.py
class pricing(CMSPluginBase):
model = mymodel
name = _("myplugin")
render_template = "template.html"
cache = False
def render(self, context, instance, placeholder):
context.update({'instance': instance})
return context
models.py
class mymodel(CMSPlugin):
firstoption = models.CharField(max_length=200)
def __str__(self):
return self.firstoption
可能是因为您需要调用all
帖子
{% for post in instance.posts.all %}
{{ post.firstoption }}
{% endfor }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.