我试图找到答案,但不能.在我的模板中,当我迭代JSONfield
{% extends "electronic/electronic_base.html" %}
{% load staticfiles %}
{% block content %}
{% for item in micro_all %}
<h1>{{item.title}}</h1>
<table class="table table-condensed">
<tbody>
<tr>
{% for key in item.attributes%}
<td>{{key}}</td>
{% endfor %}
</tr>
</tbody>
</table>
{% endfor %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
我可以得到钥匙,但不是价值.试图使用键,值和打印值,但由于某些原因,它给了我单个字母甚至不是表格格式.如何访问模板中的值
from django.db import models
from django.contrib.postgres.fields import JSONField
class Category(models.Model):
title = models.CharField(max_length = 200)
def __str__(self):
return self.title
class SubCategory(models.Model):
title = models.CharField(max_length = 200)
category = models.ForeignKey(Category)
def __str__(self):
return self.title
class Product(models.Model):
title …Run Code Online (Sandbox Code Playgroud)