我有一個存盤整數值的 cookie,我想要它:如果用戶已登錄,則顯示導航欄,否則將其隱藏。如果 cookie 存在,我還需要隱藏標簽。
uj5u.com熱心網友回復:
你可以用任何一種方式(后端或在 html 中)
html方式
{% if "cookie_name" in request.cookies %}
Code for nav show
{% else %}
Do something
{% endif %}
后端
如果您可能想這樣做
@app.route("/your_url")
def your_url():
#you could also compare the value
if "name_of_cookie" in request.cookies:
return render_template("your.html", nav = True)
else:
return render_template("your.html", nav = False)
HTML
{% if nav %}
Code for showing nav
{% else %}
Do Something
{% endif %}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/467335.html
