The scenario goes like this.
I get an atom file from a website (say A). A third party will be request this atom file through my website (say B).
I am writing a Django app which will frequently poll website A and store it as a file. Now, when a third party requests for the file through website B, I will have to display the file as xml in the browser.
My question is how do I render an entire xml file to a view in Django?
render_to_response
expects a template. I can't use a template as such. I just need to display the file in the view. How do I do this?
View an XML file in a browser If all you need to do is view the data in an XML file, you're in luck. Just about every browser can open an XML file. In Chrome, just open a new tab and drag the XML file over. Alternatively, right click on the XML file and hover over "Open with" then click "Chrome".
To view raw XML source, try to select "View Page Source" or "View Source" from the browser menu. Note: In Safari 5 (and earlier), only the element text will be displayed. To view the raw XML, you must right click the page and select "View Source".
You can add a stylesheet association processing instruction to an XML document that specifies a stylesheet for a web browser to use when displaying it. To display an XML document in a web browser: 1. You must first decide whether or not your XML document needs to reference a document type declaration (DTD).
Do something like the below:
return render(request, 'myapp/index.html', {"foo": "bar"}, content_type="application/xhtml+xml")
Just define the MIME type to 'text/xml' using the content_type argument.
return render(request, 'xmltemplate.xml', {'foo':'bar'}, content_type='text/xml')
In the xmltemplate.xml render the variables if you want.
<?xml version="1.0" encoding="UTF-8"?>
<note>
<foo>{{ foo }}</foo>
</note>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With