Hello,
    I need a view to return plain/text and I came up with the following code:

from django import http
from django.views.generic.base import TemplateResponseMixin
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView

from django.conf import settings

class PlainTextResponseMixin(TemplateResponseMixin):
    def render_to_response(self, context):
        return super(PlainTextResponseMixin, self).render_to_response(
            context,
            content_type='plain/text; charset=%s' % settings.DEFAULT_CHARSET)

class PlainTextListView(PlainTextResponseMixin, ListView):
    pass

class PlainTextDetailView(PlainTextResponseMixin, DetailView):
    pass

meant to be used as follows (for example):

    url(r'^v/(?P<slug>[-\w]+)\.bib$',
        cache_page(PlainTextDetailView.as_view(
                model=Publication,
                template_name='academic/publication_detail.bib')),
        name='academic_publishing_publication_detail_bibtex'),

Questions:
1) If I don't add `charset=%s' % settings.DEFAULT_CHARSET` the default
charset is not honored. Why?
2) could I do better or with less code? For instance, with
function-based views, all I had to do is pass a `{'mimetype':
'text/plain'}` kwarg to `object_list`

Thanks.
-F

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to