Creating a custom zip file in Django

I am working on a webapp that uses SCORM so that it can be incorporated into our clientโ€™s learning management systems. This works by creating a zip file containing multiple files. Two files depend on the specific resource they want to include and the client itself. Therefore, I would like to generate these zip files automatically, upon request.

So, imagine that I have a "template" version of ZIP extracted to a directory:

/zipdir/fileA.html
/zipdir/fileB.xml
/zipdir/static-file.jpg

Suppose I use the Django template template in filesA and fileB. I know how to run a file through the template loader and display it, but how to add this file to a ZIP file?

Can I create a base zip file (which does not have fileA and fileB) and add two renderings to it? Otherwise, how would you clone zipdir to a temporary location and then transfer these two files before they are zipped?

+3
source share
1 answer

Using zipfilec StringIOwill allow you to create a zip file in memory, which you can later send to the client.

+5
source

Source: https://habr.com/ru/post/1774540/


All Articles