Hi Ross,
On Wed, May 30, 2012 at 3:59 AM, Ross C <sendrossemail@gmail.com> wrote:
> I have a minor question and looking through the source (although maybe i
> missed it) I cant seem to see how to change the HttpResponse content_type of
> a Generic class based view.
>
> Anyone point me in the right direction or know the answer outright?
First of all check out the TemplateResponse[0] and then the
TemplateResponseMixin[1] specifically render_to_response() where you
can subclass and call super() with new kwargs. In the case you are
looking for adding 'content_type' to the kwargs, to change it to
whatever you want.
Simply add the following to your view:
def render_to_response(self, context, **response_kwargs):
response_kwargs.update({'content_type': 'yyy/xxx'})
return super(MyView, self).render_to_response(context,
**response_kwargs)
Regards,
Iván
[0] https://docs.djangoproject.com/en/dev/ref/template-response/
[1] https://docs.djangoproject.com/en/dev/ref/class-based-views/#templateresponsemixin
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment