Deploy new static files without restarting the server

Hello everyone.
I am working on a site project developed with Django and served with Waitress and Nginx. I have several static files in the site that are properly collected and served with collectstatic.
The project is integrated with an app that allows users to submit photos, which I will then need to display on the website as soon as the app user uploads them.
Unfortunately, the photos I submit are not displayed correctly, and it gives me 404 error on the photograph. If I stop and restart the webserver after a new collectstatic, the photo is displayed.
I tried inserting this line before the page render, and the log tells me that there is a new file to copy, but I still get 404.

call_command('collectstatic', interactive=False, verbosity=1)

Of course, restarting the server at each upload it’s not a suitable solution.

Any suggestions?

Thanks in advance

Welcome @goalpang !

User-uploaded files are not “static” files, they fit in the Django category of being “media” files. They are managed and handled separately from static files. You do not work with them in the same way.

See the docs at Managing files | Django documentation | Django for more details.

Yeah you are right, I have set MEDIA_ROOT and MEDIA_URL in the project, but maybe overall it is not handled in the best way in the database. Unfortunately I don’t have the time to try to fix everything so I have to come up with something tomorrow.

Thanks for the response

Hi Ken,
these are my media settings:

MEDIA_ROOT = os.path.join(BASE_DIR, 'my_app', 'media','images')
MEDIA_URL = '/media/'

However, in the db my images are stored by their path on the server, but unfortunately the column has CharField as type and not ImageField.
Am I completely doomed? Thanks

What is the Model field for those files?

Django does not store the actual files in the database. The files themselves are stored in a location determined by your settings. (Primarily MEDIA_ROOT, but other settings are involved as well.)

In addition to the docs I referenced above, you probably should also read File Uploads | Django documentation | Django and Model field reference | Django documentation | Django