I am trying to pass data from a model into a XML file. I do this like I would with a normal .html template:
def getGroups(request):
groups = SpeciesGroup.objects.all().order_by('id')
return render_to_response(
'groups.xml',
{'groups':groups},
context_instance = RequestContext(request)
)
in my groups.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Groups>
{% for g in groups %}
<group_id>{{g.id}}</group_id>
<name>{{g.name}}</name>
<description>{{g.description}}</description>
{% endfor %}
</Groups>
When loading the URL in the browser, I get a blank screen. But when I view source I get the correct data:
<?xml version="1.0" encoding="UTF-8"?>
<Groups>
<group_id>1</group_id>
<name>Small</name>
<description>Small</description>
<group_id>2</group_id>
<name>Medium</name>
<description>Medium</description>
<group_id>3</group_id>
<name>Large</name>
<description>Large</description>
</Groups>
I have validated the source XML and it’s fine. I’m assuming I have missed something or left something out in my view. I bet it’s something simple that I can’t find on a Monday morning!
I figured it out myself! All I needed was to add the mimetype in my return: