flask api response code
To set the response code in Flask API, follow these steps:
Import the necessary modules:
python from flask import Flask, jsonify
Create a Flask application:
python app = Flask(__name__)
Define a route with a function that returns the response with the desired status code:
python @app.route('/example') def example(): response = jsonify({'key': 'value'}) response.status_code = 201 return response
Run the Flask application:
python if __name__ == '__main__': app.run()