I want to raise or return a 405 Method not allowed but I cannot find how. Like in Flask you could do abort(405). Is there anyway to raise or return a Django 405 exception.
1 Answer
Ok, I found the answer. You could use what Alex has said. But you can also use the HttpResponseNotAllowed and click here for the docs.
return HttpResponseNotAllowed() If you want to return a custom one just do the following:
return render(request, "Error Pages/405.html", status=405) Notice the status, that is what will tell the browser about the code that is being returned.
1 Comment
Flimm
For 404 errors, you have a choice between throwing an
Http404 exception and returning an HttpResponseNotFound object. There is no equivalent Http405 class though, only HttpResponseNotAllowed