[Answered ]-Django tar generation on request

2👍

The tarfile module is probably a good place to start.

You would probably want to cache the file somewhere in the filesystem to save yourself from too much work. There’s no reason to regenerate the file if the contents haven’t changed.

0👍

You can use django-tarview (install via pip from PyPi, or get it from github)

Extend tarview.views.BaseTarView and implement get_files:

from tarview.views import BaseTarView

class TarView(BaseTarView):
    def get_files(self):
        return [File(open('test_file.txt'), name="test_file.txt"),
            ContentFile(b"I am a text file", name="text.txt")]

Leave a comment