Reputation: 325
How to test my custom error page for error 400 bad request in django
views.py
class Custom400View(TemplateView):
template_name = "400.html"
urls.py
handler400 = Custom400View.as_view()
Upvotes: 3
Views: 2756
Reputation: 325
please use SuspiciousOperation to raise bad request 400 error
from django.core.exceptions import SuspiciousOperation
def custom():
raise SuspiciousOperation('bad request')
Upvotes: 0
Reputation: 715
You can setup a view that just raises a SuspiciousOperation exception like this
from django.core.exceptions import SuspiciousOperation
def bad_request_view(request):
raise SuspiciousOperation
Then add a url for the view in your urls py
Link to the docs explanation: https://docs.djangoproject.com/en/2.1/topics/http/views/#testing-custom-error-views
Upvotes: 2