Refer to the Django document , you can set CSRF_FAILURE_VIEW
in your settings.py
, for example:
CSRF_FAILURE_VIEW = 'your_app_name.views.csrf_failure'
In addition, you will need to define the csrf_failure
function in your view (you must have this signature: def csrf_failure(request, reason="")
based on the document), which is similar to:
def csrf_failure(request, reason=""): ctx = {'message': 'some custom messages'} return render_to_response(your_custom_template, ctx)
And you can write your own template as:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> {{ message }} </body> </html>
source share