Python Django将json对象加载到模板
我正在从firebase获取数据 views.pyPython 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
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帖子的内容显示为(格式正确的)文本。