简体   繁体   中英

How to use parameters with Flask-Restful API

I am new to building API's and I'm struggling to use the parameters passed to this GET. The parameters come through as string:key1 and not key1 on its own. How do I get just the value?

app = Flask(__name__)
api = Api(app)

class User_Team_Endpoint(Resource):

    def get(self, key1, key2):        

        data = user_team.get_team()
        data = data[0]
        data = data.reset_index().to_json(orient='records')
        data = json.loads(data)
        return data, 200, {'Content-Type':'application/json'}


api.add_resource(User_Team_Endpoint, '/user_team_endpoint/<string:key1><string:key2>')

if __name__ == '__main__':
    app.run() # run our Flask app

You've missed a Slash on your api.add_resource

api.add_resource(User_Team_Endpoint, '/user_team_endpoint/<string:key1>/<string:key2>')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM