Question

how ill write a xml file for use with flash?, Django Doc dont have nothing about XML (just for Feeds)....

Tutorial?

Thansk

Was it helpful?

Solution

Quoting the start of the Django documentation on templates:

A template is simply a text file. It can generate any text-based format (HTML, XML, CSV, etc.).

Your view will look something like this:

from django.shortcuts import render_to_response

def your_view(request)
    context_data = {'extra': stuff}
    return render_to_response('your_xml_template.xml', context_data,
                              mimetype='application/xml')

OTHER TIPS

You can even use one of the handy generic views to easily generate XML using data from one of your models. Something like this could go into your urls.py file:

urlpatterns = ('django.views.generic.list_detail',
    (r'^mymodel-(?P<object_id>\d+).xml$', 'object_detail', {'queryset': MyModel.objects.all(),
                                                            'template_name': 'your_xml_template.xml',
                                                            'mimetype': 'application/xml'}),
   (... more url patterns ...),
)

All you have to do is write the XML template.

Or you can directly respond using a string, without templates.

def view(request):
   return HttpResponse("<xml></xml>",mimetype="application/xml")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top