开发者

Building a custom ZIP file in Django

I'm working on a webapp that uses SCORM so it can be included in our clients' learning management systems. This works by building a zip file that contains several files. Two of the files depend on the particular resource they want to include and the client themselves. I'd therefore like to generate these zip files automatically, on demand.

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

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

Let's imagine I use Django's template sytax in fileA and fileB. I know how to run a file through the template loader and render it, but how do I add that file to a ZIP file?

Could I create a base zip file (that doesn't have fileA and fileB in) and add the two renders to it? 开发者_JAVA百科Otherwise, how would you go about cloning the zipdir to a temporary location and then rendering those two files to it before zipping it?


Using zipfile with StringIO will allow you to create a zip file in memory that you can later send to the client.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜