在 pythonanywhere 中部署测试烧瓶 API
Deploying test flask API in pythonanywhere
我正在尝试在 pythonanywhere 的 flask 文档中部署示例 flask API 应用程序。
from flask import Flask, request
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
todos = {}
class TodoSimple(Resource):
def get(self, todo_id):
return {todo_id: todos[todo_id]}
def put(self, todo_id):
todos[todo_id] = request.form['data']
return {todo_id: todos[todo_id]}
api.add_resource(TodoSimple, '/<string:todo_id>')
if __name__ == '__main__':
app.run()
当我在 pycharm 本地测试这个应用程序时,我通过使用
发送数据成功执行了应用程序
curl http://localhost:5000/todo1 -d "data=Remember the milk" -X PUT
pycharm 终端中的命令。
我得到的结果是
{
"todo1": "Remember the milk"
}
但是当我使用 Postman 测试部署时,我得到的结果是
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again
Postman 中查询参数中使用的参数是:
key:data
值:"Remember the milk"
在本地执行应用得到的结果是正确的结果。
我做错了什么?
PS:
在使用 pythonanywhere 时,我使用了
http://www.mydomain.pythonanywhere.com
您需要将 http://localhost:5000/
替换为来自 pythonanywhere 的 url,例如
http://yourusername.pythonanywhere.com
那是假设你没有支付和配置你自己的域名
数据必须在 'Body' 选项卡中发送,而不是在 'Param' 选项卡中发送。
我正在尝试在 pythonanywhere 的 flask 文档中部署示例 flask API 应用程序。
from flask import Flask, request
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
todos = {}
class TodoSimple(Resource):
def get(self, todo_id):
return {todo_id: todos[todo_id]}
def put(self, todo_id):
todos[todo_id] = request.form['data']
return {todo_id: todos[todo_id]}
api.add_resource(TodoSimple, '/<string:todo_id>')
if __name__ == '__main__':
app.run()
当我在 pycharm 本地测试这个应用程序时,我通过使用
发送数据成功执行了应用程序curl http://localhost:5000/todo1 -d "data=Remember the milk" -X PUT
pycharm 终端中的命令。
我得到的结果是
{ "todo1": "Remember the milk" }
但是当我使用 Postman 测试部署时,我得到的结果是
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again
Postman 中查询参数中使用的参数是: key:data 值:"Remember the milk"
在本地执行应用得到的结果是正确的结果。 我做错了什么?
PS: 在使用 pythonanywhere 时,我使用了
http://www.mydomain.pythonanywhere.com
您需要将 http://localhost:5000/
替换为来自 pythonanywhere 的 url,例如
http://yourusername.pythonanywhere.com
那是假设你没有支付和配置你自己的域名
数据必须在 'Body' 选项卡中发送,而不是在 'Param' 选项卡中发送。