Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在my template view python django中查看redis json数据_Python_Json_Django_Redis - Fatal编程技术网

如何在my template view python django中查看redis json数据

如何在my template view python django中查看redis json数据,python,json,django,redis,Python,Json,Django,Redis,问题:如何让redis json数据显示在我的模板中?由于某种原因,我不能让它工作。任何帮助都将不胜感激 到目前为止,我的json数据被正确地保存到redis,但我仍然不知道如何在我的模板中显示它。因此,对于obj.customer_name,我希望它来自redis,并遍历我的模板的json数据 views.py home.html模板 您正在通过执行obj=json.load(cust_cache)将json转换为字典,因此在您的模板中,您应该具有以下内容: {% for key, value

问题:如何让redis json数据显示在我的模板中?由于某种原因,我不能让它工作。任何帮助都将不胜感激

到目前为止,我的json数据被正确地保存到redis,但我仍然不知道如何在我的模板中显示它。因此,对于obj.customer_name,我希望它来自redis,并遍历我的模板的json数据

views.py home.html模板
您正在通过执行
obj=json.load(cust_cache)
将json转换为字典,因此在您的模板中,您应该具有以下内容:

{% for key, values in obj.items %}

   <h3>{{ key }}</h3>
   {{ value }}
{% endfor %}
{%用于键,值在obj.items%}
{{key}}
{{value}}
{%endfor%}

作为脚注,请允许我指出,这是存储数据的更好方法。

很高兴能提供帮助。
{% extends "app/layout.html" %}

{% block content %}

<div class="jumbotron">
    <h1>Customers</h1>
</div>

<div class="row">


    <div style="width: 40%; float:left">
        {% for obj in obj.all %}
          <h3> {{obj.customer_name}} </h3>
        {% endfor %}

    </div>      
</div>

{% endblock %}
from django.db import models
import json

class Customer(models.Model):
  objects = models.Manager()
  customer_id = models.IntegerField()
  customer_name = models.CharField(max_length=255)
  created_at = models.DateField
  updated_at = models.DateField
{% for key, values in obj.items %}

   <h3>{{ key }}</h3>
   {{ value }}
{% endfor %}