G
G
German Jet2015-08-14 12:13:48
Django
German Jet, 2015-08-14 12:13:48

How to scan folders and files in a directory and output the result to a Django template?

There is a folder with the following structure:

camera  
    2015-08-01
        object
            img1.jpg
            img2.jpg
            ...
        object
            img1.jpg
            img2.jpg
            ...
    2015-08-02
        object
            img1.jpg
            img2.jpg
            ...
        object
    ....

The name of the object folder is taken from the database, the object folder itself may not exist in the camera folder.
It is required to scan the camera folder, and if there is an object in the folders with dates (2015-08-01, 2015-08-02...),
transfer the result to the template, in the template you need to display all the photos, grouped by dates.
I hope I made myself clear :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Fateev, 2015-08-14
@GeraJet

If you do it right as you described, then terrible crutches will come out, because the web server should give the pictures, and you can’t output them directly from some folder to the template. It seems to me better to write a custom management command to import these objects into the database, and then display them with a regular ListView. By cron, for example, or in some other way, run this command again for import. It seems to me that to implement such functionality, it will be necessary to write 20-30 lines of code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question