Ticket #3580: serialized.txt

File serialized.txt, 636 bytes (added by David Chandek-Stark <david.chandek.stark@…>, 17 years ago)
Line 
1def serialized(request, queryset, format, mimetype=None):
2 """
3 Serialize queryset in specified format and return via HTTP
4 Standard mimetype for format can be overridden with provided value
5 """
6 from django.http import HttpResponse
7 from django.core import serializers
8 content = serializers.serialize(format, queryset)
9 if mimetype is None:
10 if format == 'xml':
11 mimetype = 'application/xml'
12 elif format == 'json':
13 # http://www.ietf.org/rfc/rfc4627.txt
14 mimetype == 'application/json'
15 return HttpResponse(content=content, mimetype=mimetype)
Back to Top