Return different HttpResponse from direct_to_template
I've attached a patch that allows one to change the type of HttpResponse returned by the django.views.generic.simple.direct_to_template generic view. For example,
from django.http import HttpResponseForbidden
from django.views.generic.simple import direct_to_template
def forbidden_view(request):
extra = {
"some": "extra_parameter",
}
return direct_to_template(request, "custom/forbidden.html", extra_context=extra, response=HttpResponseForbidden)
I'm currently writing an application with a rather convoluted set of permissions (not by my choice) and having to render and return many different 403 forbidden pages. A lot of my different 403 forbidden pages need more (and dynamic) data embedded in them. I wrote a simple generic view to do this, and it took me a few minutes to realize I'd duplicated the direct_to_template view but substituted HttpResponseForbidden for HttpResponse.
Proposed change to direct_to_template generic view with docs change