6๐
If you donโt want to render a template, donโt do so. render
is just a shortcut to render a template. If you just want to display text, just pass it into the HttpResponse.
Since your data is in a file, this will work:
return HttpResponse(open('myxmlfile.xml').read())
although you should beware of concurrency issues, if more than one person is accessing your site at a time.
21๐
You just need to define the MIME type to 'text/xml'
using the content_type
argument:
return HttpResponse(open('myxmlfile.xml').read(), content_type='text/xml')
- Background processing in Django without Celery
- Login_required decorator in django
- Selenium: Element not clickable โฆ Other Element Would Receive Click
- Object of type 'AuthToken' is not JSON serializable
- Database table names with Django
18๐
Do something like the below:
return render(request, 'myapp/index.html', {"foo": "bar"}, content_type="application/xhtml+xml")
- Clean Up HTML in Python
- @csrf_exempt stopped working in Django 1.4
- How to return data with 403 error in Django Rest Framework?
- Django Foreign Key: get related model?
4๐
return render(request, 'products.xml', content_type='text/xml')
The render
function can also work; you must add like jdelosโ answer, simply adding the content_type='text/xml'
.
- Use Django ORM outside of Django
- Why is django's settings object a LazyObject?
- Django test: TransactionManagementError: You can't execute queries until the end of the 'atomic' block
- How to add 'collapse' to a Django StackedInline
2๐
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>
- Trouble with Django sending email though smtp.gmail.com
- Django request.user.is_superuser doesn't work