ImportError:无法从“ flask_session”导入名称“ Session”

时间:2020-07-18 10:53:07

标签: python flask python-3.7 flask-session

预先感谢您投入本期的时间

用例

  1. 我已经安装了Flask-Session pip install Flask-Session
  2. 我已在https://flasksession.readthedocs.io/en/latest/上复制/粘贴了该教程

from flask import Flask, session
from flask_session import Session

app = Flask(__name__)
# Check Configuration section for more details
SESSION_TYPE = 'redis'
app.config.from_object(__name__)
Session(app)

@app.route('/set/')
def set():
    session['key'] = 'value'
    return 'ok'

@app.route('/get/')
def get():
    return session.get('key', 'not set')

错误

python flask_session.py  Traceback (most recent call last):   
    File "flask_session.py", line 2, in <module>

from flask_session import Session   File "/flask_session.py",

line 2, in <module>
    from flask_session import Session

1 个答案:

答案 0 :(得分:0)

问题来自文件名:我将文件“ flask_session.py”重命名为“ flask_session_test.py”