I am prototyping a Django web-app that will provide a static media files (PDFs, movies and so on) to the users. One of the features I am going to implement is a dynamic URLs. The point is to generate different URLs for each access attempt. When user will request a list of files I will generate links and save them to the DB. When some of these links will be clicked I will return required content and clear links from the DB.
I suppose that serving media through the Django is far away from the best practices. Should it be avoided at all costs? Does it seems reasonable to access these files via non-Django app (Perl script or something)?
I think the question is wrongly stated.
Django is capable to serve static files, but by default it is disabled on production, and it is clearly stated it is just for development purposes.
So, everybody agrees that using django to serve static files is a bad idea 🙂
However, as you put it, you do not want to use django for serving static files, you want to use django to implement some kind of “security” on file download.
As I understand it, the file is not static at all; on the contrary, it is definitely dynamic!
I think you have two possible options:
I think the second point needs some more details.
Serving a file requires some time; using django to serve it is not less efficient than any other method (most of the time is spent in waiting for the I/O), but it may consume a thread, or a process on your server.
If you plan to have many connections at the same time, this approach may have serious drawbacks; on the other hand, if you need to serve small files to a limited audience, then it may be completely OK.