【发布时间】:2017-03-18 08:30:35
【问题描述】:
我正在试验Pyrebase,试图从 Firebase 中提取一些数据并将它们呈现在烧瓶中。这就是我的数据在 firebase database screenshot
中的样子在flask-python中,像这样检索数据并传递给render_template:
@app.route('/')
def home():
all_post = db.child("post").get().val()
for i, (key, value) in enumerate(all_post.items()):
dict = value
print(dict)
return render_template('home.html', post=dict)
此时,dict从上面的print语句看是这样的
{'postTitle': 'Second title', 'postBody': 'Second tyext'}
{'postTitle': 'Title of my post', 'postBody': 'Body of my post'}
在我的烧瓶/神社模板中,我正在循环 dict 试图呈现类似于博客文章的数据,我试图在数据库中显示每个博客标题及其正文
{% for key, value in dict.items() %}
<h2>{{ key }}</h2>
<P>{{ value }}</P>
{% endfor %}
我在尝试像上面那样渲染时遇到的错误是:
TypeError: descriptor 'items' of 'dict' object needs an argument
最好的方法是什么,或者我哪里出错了?
【问题讨论】:
标签: python dictionary firebase flask firebase-realtime-database