I want to change the default 404 code, when flask doesn't finds the route, to other code. How can I do that?
As already said, it is generally not a good idea to redefine the meaning of standard status codes.
Although you can change a status code returned, here's an example:
from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' @app.errorhandler(404) def page_not_found(error): return 'This page does not exist', 777 if __name__ == '__main__': app.run()
This will return status code 777 on any page other than /.
/
Here's a result:
More on the topic you can find here.
As already said, it is generally not a good idea to redefine the meaning of standard status codes.
Although you can change a status code returned, here's an example:
This will return status code 777 on any page other than
/
.Here's a result:
More on the topic you can find here.