Last active
August 29, 2015 14:21
-
-
Save jheasly/0f7c53eec6d92905e127 to your computer and use it in GitHub Desktop.
utf16-le encoded object_list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.http import HttpResponse | |
| from django.template import RequestContext, loader | |
| from foo.models import Baz | |
| ... | |
| def foo(request): | |
| queryset = Baz.objects.order_by('date') | |
| template_name = 'my_template.html' | |
| mimetype = 'text/plain' | |
| t = loader.get_template(template_name) | |
| c = RequestContext(request, {'object_list': queryset}) | |
| data = t.render(c) | |
| data = data.encode('utf-16le') | |
| response = HttpResponse(data, mimetype=mimetype) | |
| response['Content-Disposition'] = 'attachment; filename=InDesign_tagged_text.txt' | |
| return response | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would change the mimetype to "text/plain; charset=UTF-16LE" just to play nice, but it probably will never matter with your Content-Disposition. Also, HttpResponse's mimetype parameter has been deprecated since 1.5; use content_type instead.