diff --git a/app.py b/app.py index 89c9a8bc..187434e4 100644 --- a/app.py +++ b/app.py @@ -31,7 +31,7 @@ from routes.adminPanelComments import adminPanelCommentsBlueprint from routes.changeProfilePicture import changeProfilePictureBlueprint from dbChecker import dbFolder, usersTable, postsTable, commentsTable -from flask_wtf.csrf import CSRFProtect +from flask_wtf.csrf import CSRFProtect, CSRFError dbFolder() usersTable() @@ -56,6 +56,11 @@ def notFound(e): return render_template("404.html"), 404 +@app.errorhandler(CSRFError) +def handle_csrf_error(e): + return render_template("csrfError.html", reason=e.description), 400 + + app.register_blueprint(postBlueprint) app.register_blueprint(userBlueprint) app.register_blueprint(indexBlueprint) diff --git a/templates/csrfError.html b/templates/csrfError.html new file mode 100644 index 00000000..c25ffc69 --- /dev/null +++ b/templates/csrfError.html @@ -0,0 +1,11 @@ +{% extends 'layout.html'%} {%block head%} + +{% endblock head %} {%block body%} +
+

Fill the same form again.

+

Reason: {{reason}}

+
+{% endblock body %}