這是我的應用程式中的一個函式,它從資料庫中回傳一個數字,我正在嘗試使用燒瓶在我的網頁上顯示它
def handler():
increment_visitor()
return retrieve_visitor_count()
@app.route('/')
def home():
handler()
return render_template("index.html", count=handler)
我將名稱計數分配給處理程式并嘗試在我的 index.html 檔案中顯示計數,如下所示:
<p>{{count}}</p>
當我加載我的網頁時,輸出如下
<function handler at 0x7f8c70069a60>
當我列印我的處理函式時,它會輸出適當的數字,那么如何讓該數字正確顯示在我的網頁上?
uj5u.com熱心網友回復:
count是處理程式,它是一個函式。添加括號以在模板中呼叫它,如下所示:
{{count()}}
不過,看看你的邏輯,我想你可能想要這樣的東西:
@app.route('/')
def home():
result = handler()
return render_template("index.html", count=result)
否則,您可能會將訪問者計數增加兩次
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/496549.html
上一篇:單擊按鈕時無法將影像更改為攝像機
下一篇:我無法解決這個錯誤:jinja2.exceptions.UndefinedError:'user'isundefined
