Zipping dynamic files in App Engine (Python)

后端 未结 3 1469
孤街浪徒
孤街浪徒 2021-01-03 01:01

Is there anyway I can zip dynamically generated content, such as a freshly rendered html template, into a zip file using zipfile?

There seem to be some examples arou

3条回答
  •  醉酒成梦
    2021-01-03 01:40

    You can add whatever you want to a zip file using ZipFile.writestr():

    my_data = "

    Hello, world!

    " z.writestr("hello.html", my_data)

    You can also use sub-folders using / (or os.sep) as a separator:

    z.writestr("site/foo/hello/index.html", my_data)
    

提交回复
热议问题