【发布时间】:2014-02-14 09:19:27
【问题描述】:
我有这样的查询集:
hello = Hello.objects.all()
在模板中我会这样做来获取数据:
{% for h in hello %}
{% for i in h.data %} #data is stored like this ['a', 'b', 'c'] --> I want to access individual componenet, thus I would do:
{{i}}
{% endfor %}
{% endfor %}
但不是将数据生成为:
a
b
c
它产生为['a', 'b', 'c']
怎么了?我有理由将数据存储在列表中。如何分别访问每个数据。谢谢
目的:
颜色在数据字段中存储为:[black, green, brown]
因此我想实现:
div style="color: black"
div style="color: green"
div style="color: brown"
编辑
models.py
类你好(模型。模型):
用户 = 模型。外键(用户)
数据 = models.CharField(max_length=255)
def __str__(self):
return "%s's decoration photos" % self.user
【问题讨论】:
-
能否提供models.py源代码?
-
好的先生,请看我编辑的问题。
标签: django django-queryset django-templates