S
S
Sergey Ganzhela2021-04-29 21:36:20
Django
Sergey Ganzhela, 2021-04-29 21:36:20

How to convert large object to xml file?

In a project I'm using
data = render_to_string("****.xml", products)
The product object got too big and the process is being killed at runtime.
How to deal with it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2021-05-01
@Sergiy_Hanzhela

  1. Use queryset.iterator() to get rid of storing the whole list of objects
  2. Use StreamingHTTPResponse to not buffer all output
  3. Form XML not entirely using a cycle in the template, but one element at a time (plus XML header / footer)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question