Opened 15 years ago

Closed 14 years ago

Last modified 14 years ago

#12669 closed (fixed)

Return different HttpResponse from direct_to_template

Reported by: Kyle Dodson 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: no UI/UX: no

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 Kyle Dodson 15 years ago.
Proposed change to direct_to_template generic view with docs change
patch_ticket14390.diff (7.6 KB ) - added by Łukasz Rekucki 14 years ago.
Patch with docs and tests.

Download all attachments as: .zip

Change History (5)

by Kyle Dodson, 15 years ago

Attachment: direct_to_template.diff added

Proposed change to direct_to_template generic view with docs change

comment:1 by Russell Keith-Magee, 15 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted
Version: SVN

comment:2 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: newclosed

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

by Łukasz Rekucki, 14 years ago

Attachment: patch_ticket14390.diff added

Patch with docs and tests.

comment:3 by Łukasz Rekucki, 14 years ago

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

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