Skip to content
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