<p>How can I show a web page in a transparent window and have the white part of the web page also transparent.</p>

[{'answer_id': 67477, 'author': 'Andy Ross', 'author_id': 9555, 'author_profile': 'https://Stackoverflow.com/users/9555', 'pm_score': -1, 'selected': False, 'text': '<p>Can\'t you just write a link to a "zip server" or whatnot?  Why does the zip archive itself need to be served from Django?  A 90\'s era CGI script to generate a zip and spit it to stdout is really all that\'s required here, at least as far as I can see.</p>\n'}, {'answer_id': 67527, 'author': 'Cristian', 'author_id': 680, 'author_profile': 'https://Stackoverflow.com/users/680', 'pm_score': 3, 'selected': False, 'text': '<p>Django doesn\'t directly handle the generation of dynamic content (specifically Zip files). That work would be done by Python\'s standard library. You can take a look at how to dynamically create a Zip file in Python <a href="https://docs.python.org/2/library/zipfile.html#zipfile-objects" rel="nofollow noreferrer">here</a>.</p>\n\n<p>If you\'re worried about it slowing down your server you can cache the requests if you expect to have many of the same requests. You can use Django\'s <a href="http://docs.djangoproject.com/en/dev/topics/cache/#topics-cache" rel="nofollow noreferrer">cache framework</a> to help you with that.</p>\n\n<p>Overall, zipping files can be CPU intensive but Django shouldn\'t be any slower than another Python web framework.</p>\n'}, {'answer_id': 72180, 'author': 'zgoda', 'author_id': 12138, 'author_profile': 'https://Stackoverflow.com/users/12138', 'pm_score': 7, 'selected': True, 'text': '<p>The solution is as follows.</p>\n\n<p>Use Python module <a href="https://docs.python.org/3/library/zipfile.html" rel="noreferrer">zipfile</a> to create zip archive, but as the file specify <a href="https://docs.python.org/3/library/io.html#io.StringIO" rel="noreferrer">StringIO</a> object (ZipFile constructor requires file-like object). Add files you want to compress. Then in your Django application return the content of StringIO object in <code>HttpResponse</code> with mimetype set to <code>application/x-zip-compressed</code> (or at least <code>application/octet-stream</code>). If you want, you can set <code>content-disposition</code> header, but this should not be really required.</p>\n\n<p>But beware, creating zip archives on each request is bad idea and this may kill your server (not counting timeouts if the archives are large). Performance-wise approach is to cache generated output somewhere in filesystem and regenerate it only if source files have changed. Even better idea is to prepare archives in advance (eg. by cron job) and have your web server serving them as usual statics.</p>\n'}, {'answer_id': 73617, 'author': 'carefulweb', 'author_id': 12683, 'author_profile': 'https://Stackoverflow.com/users/12683', 'pm_score': 2, 'selected': False, 'text': '<p>I suggest to use separate model for storing those temp zip files. You can create zip on-fly, save to model with filefield and finally send url to user.</p>\n\n<p>Advantages:</p>\n\n<ul>\n<li>Serving static zip files with django media mechanism (like usual uploads).</li>\n<li>Ability to cleanup stale zip files by regular cron script execution (which can use date field from zip file model).</li>\n</ul>\n'}, {'answer_id': 12951461, 'author': 'dbr', 'author_id': 745, 'author_profile': 'https://Stackoverflow.com/users/745', 'pm_score': 6, 'selected': False, 'text': '<p>Here\'s a Django view to do this:</p>\n\n<pre><code>import os\nimport zipfile\nimport StringIO\n\nfrom django.http import HttpResponse\n\n\ndef getfiles(request):\n    # Files (local path) to put in the .zip\n    # FIXME: Change this (get paths from DB etc)\n    filenames = ["/tmp/file1.txt", "/tmp/file2.txt"]\n\n    # Folder name in ZIP archive which contains the above files\n    # E.g [thearchive.zip]/somefiles/file2.txt\n    # FIXME: Set this to something better\n    zip_subdir = "somefiles"\n    zip_filename = "%s.zip" % zip_subdir\n\n    # Open StringIO to grab in-memory ZIP contents\n    s = StringIO.StringIO()\n\n    # The zip compressor\n    zf = zipfile.ZipFile(s, "w")\n\n    for fpath in filenames:\n        # Calculate path for file in zip\n        fdir, fname = os.path.split(fpath)\n        zip_path = os.path.join(zip_subdir, fname)\n\n        # Add file, at correct path\n        zf.write(fpath, zip_path)\n\n    # Must close zip for all contents to be written\n    zf.close()\n\n    # Grab ZIP file from in-memory, make response with correct MIME-type\n    resp = HttpResponse(s.getvalue(), mimetype = "application/x-zip-compressed")\n    # ..and correct content-disposition\n    resp[\'Content-Disposition\'] = \'attachment; filename=%s\' % zip_filename\n\n    return resp\n</code></pre>\n'}, {'answer_id': 26658291, 'author': 'Thibault J', 'author_id': 665797, 'author_profile': 'https://Stackoverflow.com/users/665797', 'pm_score': 3, 'selected': False, 'text': '<p>Shameless plug: you can use <a href="https://github.com/thibault/django-zipview">django-zipview</a> for the same purpose.</p>\n\n<p>After a <code>pip install django-zipview</code>:</p>\n\n<pre><code>from zipview.views import BaseZipView\n\nfrom reviews import Review\n\n\nclass CommentsArchiveView(BaseZipView):\n    """Download at once all comments for a review."""\n\n    def get_files(self):\n        document_key = self.kwargs.get(\'document_key\')\n        reviews = Review.objects \\\n            .filter(document__document_key=document_key) \\\n            .exclude(comments__isnull=True)\n\n        return [review.comments.file for review in reviews if review.comments.name]\n</code></pre>\n'}, {'answer_id': 40076866, 'author': 'pitaside', 'author_id': 4380481, 'author_profile': 'https://Stackoverflow.com/users/4380481', 'pm_score': 3, 'selected': False, 'text': '<p>For python3 i use the <strong>io.ByteIO</strong> since <strong>StringIO</strong> is deprecated  to achieve this. Hope it helps.</p>\n\n<pre><code>import io\n\ndef my_downloadable_zip(request):\n    zip_io = io.BytesIO()\n    with zipfile.ZipFile(zip_io, mode=\'w\', compression=zipfile.ZIP_DEFLATED) as backup_zip:\n        backup_zip.write(\'file_name_loc_to_zip\') # u can also make use of list of filename location\n                                                 # and do some iteration over it\n     response = HttpResponse(zip_io.getvalue(), content_type=\'application/x-zip-compressed\')\n     response[\'Content-Disposition\'] = \'attachment; filename=%s\' % \'your_zipfilename\' + ".zip"\n     response[\'Content-Length\'] = zip_io.tell()\n     return response\n</code></pre>\n'}, {'answer_id': 49220016, 'author': 'Antoine Pinsard', 'author_id': 1529346, 'author_profile': 'https://Stackoverflow.com/users/1529346', 'pm_score': 5, 'selected': False, 'text': "<p>Many answers here suggest to use a <code>StringIO</code> or <code>BytesIO</code> buffer. However this is not needed as <code>HttpResponse</code> is already a file-like object:</p>\n<pre><code>response = HttpResponse(content_type='application/zip')\nzip_file = zipfile.ZipFile(response, 'w')\nfor filename in filenames:\n    zip_file.write(filename)\nresponse['Content-Disposition'] = 'attachment; filename={}'.format(zipfile_name)\nreturn response\n</code></pre>\n<p>Note that you should <strong>not</strong> call <code>zip_file.close()</code> as the open &quot;file&quot; is <code>response</code> and we definitely don't want to close it.</p>\n"}, {'answer_id': 51655455, 'author': 'Pasha M', 'author_id': 8992267, 'author_profile': 'https://Stackoverflow.com/users/8992267', 'pm_score': 3, 'selected': False, 'text': '<p>I used <strong>Django 2.0</strong> and <strong>Python 3.6</strong>.</p>\n\n<pre><code>import zipfile\nimport os\nfrom io import BytesIO\n\ndef download_zip_file(request):\n    filelist = ["path/to/file-11.txt", "path/to/file-22.txt"]\n\n    byte_data = BytesIO()\n    zip_file = zipfile.ZipFile(byte_data, "w")\n\n    for file in filelist:\n        filename = os.path.basename(os.path.normpath(file))\n        zip_file.write(file, filename)\n    zip_file.close()\n\n    response = HttpResponse(byte_data.getvalue(), content_type=\'application/zip\')\n    response[\'Content-Disposition\'] = \'attachment; filename=files.zip\'\n\n    # Print list files in zip_file\n    zip_file.printdir()\n\n    return response\n</code></pre>\n'}, {'answer_id': 58849165, 'author': 'yspreen', 'author_id': 2585092, 'author_profile': 'https://Stackoverflow.com/users/2585092', 'pm_score': 0, 'selected': False, 'text': '<p>A lot of contributions were made to the topic already, but since I came across this thread when I first researched this problem, I thought I\'d add my own two cents.</p>\n\n<p>Integrating your own zip creation is probably not as robust and optimized as web-server-level solutions. At the same time, we\'re using Nginx and it doesn\'t come with a module out of the box.</p>\n\n<p>You can, however, compile Nginx with the mod_zip module (see <a href="https://hub.docker.com/r/yspreen/nginx" rel="nofollow noreferrer">here</a> for a docker image with the latest stable Nginx version, and an alpine base making it smaller than the default Nginx image). This adds the zip stream capabilities.</p>\n\n<p>Then Django just needs to serve a list of files to zip, all done!\nIt is a little more reusable to use a library for this file list response, and django-zip-stream offers just that.</p>\n\n<p>Sadly it never really worked for me, so I started a <a href="https://github.com/y-spreen/django-zip-stream" rel="nofollow noreferrer">fork</a> with fixes and improvements.</p>\n\n<p>You can use it in a few lines:</p>\n\n<pre><code>def download_view(request, name=""):\n    from django_zip_stream.responses import FolderZipResponse\n    path = settings.STATIC_ROOT\n    path = os.path.join(path, name)\n\n    return FolderZipResponse(path)\n</code></pre>\n\n<p>You need a way to have Nginx serve all files that you want to archive, but that\'s it.</p>\n'}]
['https://Stackoverflow.com/questions/67457', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/44972/']