A
A
Alex Xmel2020-07-03 11:57:14
Django
Alex Xmel, 2020-07-03 11:57:14

How to properly return XML from django?

There is some data that needs to be sent to the endpoint in XML format.
I looked at the documentation, but apart from giving the structure of the model and the sitemap, I did not find anything. I took the standard Python library xml.etree.ElementTree and did everything with its help, but still I want to know if it is possible to make the xml file I need using django ?

And the second question, the main one - how can I send this data to the endpoint, so that when I go to the address domain.ru/xml I get xml and not html. I tried a lot of options, but the output is always html. Ideally, I need an analogue of JsonResponse from django.http, but for xml. Tell me, is there something different?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-07-03
@Desead

But I don’t understand the problem and what does “using django” mean? Well, do it through templates, though there is a chance to generate invalid xml. The lxml library will be more accurate, but tedious, you can generally use something like json2xml. There are many options and they depend on the specific task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question