Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#12669 closed (fixed)

Return different HttpResponse from direct_to_template

Reported by: seniorquico Owned by: nobody
Component: Generic views Version:
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

Description

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.

Attachments (2)

direct_to_template.diff (2.3 KB) - added by seniorquico 5 years ago.
Proposed change to direct_to_template generic view with docs change
patch_ticket14390.diff (7.6 KB) - added by lrekucki 5 years ago.
Patch with docs and tests.

Download all attachments as: .zip

Change History (5)

Changed 5 years ago by seniorquico

Proposed change to direct_to_template generic view with docs change

comment:1 Changed 5 years ago by russellm

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Version SVN deleted

comment:2 Changed 5 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

Function-based generic views were deprecated by the introduction of class-based views in [14254]. Class-based views should solve this problem.

Changed 5 years ago by lrekucki

Patch with docs and tests.

comment:3 Changed 5 years ago by lrekucki

Oh my, wrong ticket :( Sorry for the mess.

Note: See TracTickets for help on using tickets.
Back to Top