Django

Code

Ticket #2000 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

[patch] allow generic views to respond with non text/html content types

Reported by: ian@holsman.net Assigned to: jacob
Milestone: Component: Generic views
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

I needed to have a page respond with a text/plain content type. here's the patch

Index: views/generic/list_detail.py
===================================================================
--- views/generic/list_detail.py        (revision 2970)
+++ views/generic/list_detail.py        (working copy)
@@ -6,7 +6,8 @@
 
 def object_list(request, queryset, paginate_by=None, allow_empty=False,
         template_name=None, template_loader=loader,
-        extra_context={}, context_processors=None, template_object_name='object'):
+        extra_context={}, context_processors=None, template_object_name='object',
+        mimetype=None):
     """
     Generic list of objects.
 
@@ -73,12 +74,13 @@
         model = queryset.model
         template_name = "%s/%s_list.html" % (model._meta.app_label, model._meta.object_name.lower())
     t = template_loader.get_template(template_name)
-    return HttpResponse(t.render(c))
+    return HttpResponse(t.render(c), mimetype=mimetype)
 
 def object_detail(request, queryset, object_id=None, slug=None,
         slug_field=None, template_name=None, template_name_field=None,
         template_loader=loader, extra_context={},
-        context_processors=None, template_object_name='object'):
+        context_processors=None, template_object_name='object',
+        mimetype=None):
     """
     Generic list of objects.
 
@@ -113,6 +115,6 @@
             c[key] = value()
         else:
             c[key] = value
-    response = HttpResponse(t.render(c))
+    response = HttpResponse(t.render(c), mimetype=mimetype)
     populate_xheaders(request, response, model, getattr(obj, obj._meta.pk.name))
     return response

Attachments

Change History

05/24/06 23:21:56 changed by anonymous

  • owner changed from adrian to jacob.
  • component changed from Admin interface to Generic views.

05/25/06 02:02:22 changed by anonymous

  • summary changed from allow generic views to respond with non text/html content types to [patch] allow generic views to respond with non text/html content types.

05/25/06 05:33:28 changed by EspenG

Should not a default mimetype be set in stead of None?

05/25/06 07:04:22 changed by ian@holsman.net

Hi Espen, passing 'None' to HttpResponse *is* the default, and lets HttpResponse figure out the correct default.

05/26/06 03:29:58 changed by EspenG

Sorry about that then. I taugth that when the default was 'None' I had to pass along a mimetype every time, but as you say that was wrong then.

05/31/06 10:08:07 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

(In [3022]) Fixed #2000 -- Added 'mimetype' parameter to generic views. Thanks, Ian Holsman

06/12/06 06:00:18 changed by URL

  • type deleted.

Add/Change #2000 ([patch] allow generic views to respond with non text/html content types)




Change Properties
Action