如标题所述,情况是这样:
烧瓶服务器
app = flask.Flask(__name__, static_folder='static')
SESSION_TYPE = 'filesystem'
app.config.from_object(__name__)
logger = logging.getLogger(__name__)
app.secret_key = 'v3563vt3vg3vf3rfgb4ty456b35453b54t3gfefert35'
CORS(app, resources={
r"/*": {
"origins": "*"
}
}, supports_credentials=True)
socketio = SocketIO(app, engineio_logger=True, logger=True)
@app.route('/login', methods=['GET', 'POST'])
def login():
json_data = request.get_json()
session['email'] = json_data['email']
session['name'] = json_data['name']
return "authenticated"
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', 'http://localhost:8080')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
response.headers.add('Access-Control-Allow-Credentials', 'true')
return response
@app.route('/checkDatabase', methods=['GET', 'POST'])
def check_database():
to_check = os.path.join(os.getcwd(), "database_" + session['email'])
to_send = ""
if os.path.exists(to_check):
to_send += "database found"
else:
to_send += "database NOT found"
return to_send
vuejs前端
let form = JSON.stringify(this.form);
this.axios
.create({ withCredentials: true })
.post("http://localhost:6543/login", JSON.parse(form), {
headers: {
},
})
从POSTMAN调用两个API,flask可以成功存储它们的值,因为第二个调用返回了所需的答案。 当在本地主机:8080浏览器页面上从vuejs调用它们时,我在主服务器上收到错误消息,因为它显示KeyError'email'。
我尝试了所有在网络上找到的解决方案,但没有成功。我在做什么错了?