Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix csrf.error_handler example in docs #243

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/csrf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ But if the template has no forms, you still need a csrf token:
Whenever a CSRF validation fails, it will return a 400 response. You can
customize the error response::

from flask import abort
from werkzeug.wrappers import Response

@csrf.error_handler
def csrf_error(reason):
return render_template('csrf_error.html', reason=reason), 400
abort(Response(render_template('csrf_error.html', reason=reason),
status=400, content_type='text/html'))

We strongly suggest that you protect all your views with CSRF. But if
needed, you can exclude some views using a decorator::
Expand Down