我正在試驗Pyrebase,試圖從Firebase中提取一些數據並將它們呈現在燒瓶中。這是我的數據怎麼看起來火力database screenshot蟒蛇 - 如何在燒瓶中呈現Firebase字典
在燒瓶蟒蛇,檢索數據並傳遞給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)
此時,字典看起來像這樣從上面
print語句{'postTitle': 'Second title', 'postBody': 'Second tyext'}
{'postTitle': 'Title of my post', 'postBody': 'Body of my post'}
在我的瓶/神社模板,我的循環字典試圖使這就像一個博客帖子,在那裏我想顯示每個博客的標題數據和它的數據庫中的正文
{% for key, value in dict.items() %}
<h2>{{ key }}</h2>
<P>{{ value }}</P>
{% endfor %}
試圖使像上面時,我得到的錯誤給出:
TypeError: descriptor 'items' of 'dict' object needs an argument
什麼是去它的最好辦法,還是我哪裏出了錯?
謝謝了,這是一個愚蠢的,我改post.items(),但是它呈現的只是一個職位,我有兩個交在數據庫中。 – joke4me
@ joke4me看看我的更新。 – Vallentin
我的循環仍然不正確我想,請你看看請 – joke4me