添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
有情有义的大白菜  ·  python ...·  3 周前    · 
完美的馒头  ·  python QTreeWidget ...·  3 周前    · 
失眠的烤红薯  ·  python qt textBrowser ...·  3 周前    · 
帅气的领带  ·  【Pyspark ...·  4 天前    · 
近视的橙子  ·  python ...·  2 天前    · 
要出家的煎饼果子  ·  The event loop - ...·  2 月前    · 
深情的脆皮肠  ·  warning: ...·  7 月前    · 
一直单身的海豚  ·  qstringlist 查找-掘金·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Im attempting to create a website in flask. To do that, I need use sessions and therefore I am required to use a secret key. I did all of that, and yet it still returns a long error log with nameerror: name ‘session’ is not defined at then end

I tried everything and moved the thing that sets the secret key everywhere, but it always had the same issue. Here is my code currently:

from flask import Flask import os app = Flask(__name__) app.secret_key = os.urandom(24) usernumber = 0 @app.route('/') def homepage(): global usernumber session['usernumber'] = usernumber usernumber = usernumber + 1 Usernumberstring = session['usernumber'] return f"Welcome {Usernumberstring}" if __name__ == '__main__': app.run(use_reloader=True, debug=False, host="0.0.0.0") If you will eventually deploy your app in a multi-process setup, your random initialization of the secret key won't work. Klaus D. Jan 31, 2021 at 8:40

You are not importing session;

from flask import Flask, session

Check more details about flask session here;

https://pythonbasics.org/flask-sessions/#:~:text=Unlike%20cookies%2C%20Session%20(session),temporary%20directory%20on%20the%20server .

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .