我在本地运行Flask-Restful API并从不同的端口发送包含JSON的POST请求.我收到了错误
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Run Code Online (Sandbox Code Playgroud)
但是,当我跑
curl --include -X OPTIONS http://localhost:5000/api/comments/3
--header Access-Control-Request-Method:POST
--header Access-Control-Request-Headers:Content-Type
--header Origin:http://localhost:8080
Run Code Online (Sandbox Code Playgroud)
我明白了
HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Allow: HEAD, GET, POST, OPTIONS
Access-Control-Allow-Origin: http://localhost:8080
Access-Control-Allow-Methods: DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT
Vary: Origin
Access-Control-Allow-Headers: Content-Type
Content-Length: 0
Run Code Online (Sandbox Code Playgroud)
其中"Access-Control-Allow-Origin"显示为"*".GET工作正常,只是POST给出了这个错误.怎么可能出错?如果相关,对于我正在使用的前端做出反应并通过axios请求.
我有一个与 SQLAlchemy 一起使用的预先存在的数据库,因此我使用 automap 从数据库中获取模型。向这些类添加方法的最佳方法是什么?例如,对于 User 类,我想添加验证密码等方法。另外,我想添加烧瓶登录(UserMixin)方法的方法。