How to call a python flask function which is call by a post request? How to call a python flask function which is call by a post request? flask flask

How to call a python flask function which is call by a post request?


Based on the signature, tis function only accepts keyword arguments.

def your_method(**kwargs):

You call it with positional arguments.

your_method('hello', 'world')

You either need to change the signature

def your_method(*args, **kwargs)

or call it differently

your_method(something='hello', something_else='world')


You cannot do this. Methods decorated with the route decorator cannot accept arguments passed in by you. View function arguments are reserved for route parameters, like the following:

@app.route('/user/<username>')def show_user_profile(username):    # show the user profile for that user    return 'User %s' % username@app.route('/post/<int:post_id>')def show_post(post_id):    # show the post with the given id, the id is an integer    return 'Post %d' % post_id

Moreover, Flask does not want you to call on these methods directly, they are intended to be executed only in response to a request input from Flask.

A better practice would be to abstract whatever logic you are trying to do into another function.