문제

How do I create an api call that does something like:

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

It is not clear how I can handle it from within:

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

Also, I noticed I can only add_resource to one level:

api.add_resource(MyResource, '/myresource') # this works
api.add_resource(MyResource, '/myresource/test') # this this not work
도움이 되었습니까?

해결책

You can find everything you need in the 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')
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top