Django Create Wizard: Deleting Temporary Files Saved in Steps

I am using django (1.4) formwizard for my application. In step 1, I upload 2 files. These files are used in the second stage. Everything works fine, but it's ---> "When I complete all the steps OR I stop after step 1, I still have temporary files stored in the MEDIA directory"

How can I guarantee that these files will be deleted in any case?

+6
source share
2 answers

Django says about the documentation that you need to manage these files yourself, therefore:

You can set the boot path to / tmp (if you are using Linux) so that they are automatically deleted.

Another approach is that you can write a script to run and delete periodically.

+2
source

You need to make 2 steps of the decision.

The first step is to set the file_storage variable with parameters in the wizardโ€™s file_storage to identify the wizardโ€™s execution, to avoid errors in the previous steps that you said in the last comment.

And then in the done() function in the wizard, delete the entire contents of the folder (do not forget to use some unique scheme for each wizard when executing), so you can delete all the files in submit before you finish the wizard.

0
source

Source: https://habr.com/ru/post/950361/


All Articles