Code

Opened 4 years ago

Closed 4 years ago

Last modified 4 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 4 years ago.
Proposed change to direct_to_template generic view with docs change
patch_ticket14390.diff (7.6 KB) - added by lrekucki 4 years ago.
Patch with docs and tests.

Download all attachments as: .zip

Change History (5)

Changed 4 years ago by seniorquico

Proposed change to direct_to_template generic view with docs change

comment:1 Changed 4 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 4 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 4 years ago by lrekucki

Patch with docs and tests.

comment:3 Changed 4 years ago by lrekucki

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.