开发者

Is there a default template for dumping data from a view

开发者 https://www.devze.com 2023-01-10 17:46 出处:网络
I hav开发者_如何学运维e complex models and would like to just \'dump\' some querysets to see exactly what they contain from view code.

I hav开发者_如何学运维e complex models and would like to just 'dump' some querysets to see exactly what they contain from view code.

I tried the generic list_detail (from urls.py) - but it appears to require writing a template.

Is there a way to dump data from a view (like how json is saved) that will work with anything passed?


You could serialize the queryset to XML and then return that in the response. Something like:

from django.core import serializers

def view(request):
    xml = serializers.serialize('xml', FooModel.objects.all())
    response = HttpResponse(xml, mimetype='application/xml')
    return response


Have you looked into the built-in databrowse app?

0

精彩评论

暂无评论...
验证码 换一张
取 消