How To Handle 404 Error In Python Flask
from flask import Flask, render_template #from flask import jsonify app = Flask(__name__) @app.route("/") def hello(): return "Welcome to Python Flask." @app.errorhandler(404) def invalid_route(e): #return "Invalid route." #return jsonify({'errorCode' : 404, 'message' : 'Route not found'}) return render_template('404.html') if __name__ == '__main__': app.run(debug=True)
//404.html <!DOCTYPE html> <html> <head> <title>404</title> </head> <body> <p><h1>404 Page not found</h1></p> </body> </html>