def error_handler(self, view):
"""Register a function that will generate the response for CSRF errors.
.. deprecated:: 0.14
Use the standard Flask error system with
``@app.errorhandler(CSRFError)`` instead. This will be removed in
version 1.0.
The function will be passed one argument, ``reason``. By default it will
raise a :class:`~flask_wtf.csrf.CSRFError`. ::
@csrf.error_handler
def csrf_error(reason):
return render_template('error.html', reason=reason)
Due to historical reasons, the function may either return a response
or raise an exception with :func:`flask.abort`.
"""
warnings.warn(FlaskWTFDeprecationWarning(
'"@csrf.error_handler" is deprecated. Use the standard Flask error '
'system with "@app.errorhandler(CSRFError)" instead. This will be'
'removed in 1.0.'
), stacklevel=2)
@wraps(view)
def handler(reason):
response = current_app.make_response(view(reason))
raise CSRFError(response.get_data(as_text=True), response=response)
self._error_response = handler
return view
评论列表
文章目录