Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.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
Python Django将json对象加载到模板_Python_Django_Firebase_Firebase Realtime Database - Fatal编程技术网

Python Django将json对象加载到模板

Python Django将json对象加载到模板,python,django,firebase,firebase-realtime-database,Python,Django,Firebase,Firebase Realtime Database,我正在从firebase获取数据 views.py def posts (request): _posts= ref.child('posts').get(); #getting data from firebase #_posts={u'1536855154789': # {u'content': u'Yahoo! The sports day is near!!', # u'image': u'https://firebas

我正在从firebase获取数据

views.py

def posts (request):
     _posts= ref.child('posts').get();  #getting data from firebase
     #_posts={u'1536855154789': 
     #      {u'content': u'Yahoo! The sports day is near!!', 
     #       u'image': u'https://firebasestorage.googleapis.com/.../img_1536855147507.jpeg?', 
     #       u'title': u'Sports Day'}, 
     #u'-LMJBAc3iZRklICAwDC1': 
     #     {u'content': u'Find the chef in your child. Food fest is here!!', 
     #      u'image': u'https://firebasestorage.googleapis.com/.../img_1536863277649.jpeg?', 
     #      u'title': u'Food Fest '}, 
     #u'-LNaLKKqSIZHraf3oedT': 
     #     {u'content': u'Exploring is part of education. Hence a tour to Historical and Cultural Heritage monuments in Delhi has been planned.',
     #      u'image': u'https://firebasestorage.googleapis.com/.../img_1538241669221.jpeg', 
     #      u'title': u'Educational Tour'}}
     return render(request, 'post.html', {'postList': _posts})
index.html

 {% for item in postList %}
 {{ item.title}}</br>
 {% endfor %}
{%for postList%中的项]
{{item.title}
{%endfor%}
它一无所获

我的firebase数据


帮我解决这个问题。提前感谢

如果你有一个dict列表,你的代码就可以运行了。但你没有;您只有一个字典,它的键是id,值本身就是dicts。因此,您需要迭代dict值:

 {% for item in postList.values %}
 {{ item.title}}</br>
 {% endfor %}
{%for postList.values%}
{{item.title}
{%endfor%}
该屏幕截图没有帮助。将
\u帖子的内容显示为(格式正确的)文本。