python - 如何在python中为flask-restful添加参数?

标签 python flask flask-restful

如何创建执行类似以下操作的 api 调用:

api.add_resource(MyResource, '/myresource/<myurlparameter>')

不清楚我如何从内部处理它:

class MyResource(restful.Resource):
    def get(self):
        print myurlparameter
        return ""

此外,我注意到我只能将 add_resource 添加到一个级别:

api.add_resource(MyResource, '/myresource') # this works
api.add_resource(MyResource, '/myresource/test') # this this not work

最佳答案

您可以在 docs 中找到您需要的一切.

Parameter in requests

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>')

Few endpoints

api.add_resource(HelloWorld,
    '/',
    '/hello')

关于python - 如何在python中为flask-restful添加参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21106965/

相关文章:

python - Python 解释器是否将实例绑定(bind)到方法或 self 参数?

python - pandas DataFrame 类型转换

python - 无法在 eclipse 下使用 matplotlib 显示绘图

python - 如何使用 Flask_login.login_required 装饰器客户端

使用 Flask 和 MySQL 的 Python 在不活动一段时间后超时

python - wsgi 文件上的语法错误(使用 apache 设置 Flask 应用程序)

python - flask Restful : dynamical parameter with POST

python - 使用 Web(Html css) 和 Python 进行人脸检测

python - 在 PyCharm 中使用 Flask-RESTful

python - matplotlib 两个传说出情节