我想转换字符串在Django模板列表:如何转换字符串中的Django模板列出
数据:
{u'productTitle': u'Gatsby Hard Hair Gel 150g', u'productPrice': 0.0, u'productMRP': 75.0, u'hasVariants': 0, u'productSite': u'http://www.365gorgeous.in/', u'productCategory': u'', u'currency': u'INR', u'productURL': u'http://www.365gorgeous.in/gatsby-hard-hair-gel-300g-1.html', u'productDesc': u'A Water type hair gel with is hard setting and gives hair a firm hold It is non sticky hard setting and smooth to the touch Firm hold with wet look spikes', u'productSubCategory': u'', u'availability': 0, u'image_paths': u'["full/548bc0f93037bd03340e11e8b18de33b414efbca.jpg"]'}
我想从上面的字典中提取图像路径,但图像路径在串u'["full/548bc0f93037bd03340e11e8b18de33b414efbca.jpg"]'
是有什么办法可以把它转换成["full/548bc0f93037bd03340e11e8b18de33b414efbca.jpg"]
内模板...我知道它可以在视图中进行,但我可以做这个模板....
请问为什么这是一个字符串呢? – rantanplan
......以及为什么你不想将逻辑放在你的视图中它属于哪里? – arie
我同意这种事情不应该由模板处理。如果你将它存储为json,当你访问该字段时,会有很多包将自动处理序列化和反序列化。下面是一个例子:https://github.com/bradjasper/django-jsonfield – Ngenator