How to reload staticfiles.json without restarting Django?

I have a Django app deployed via docker image on Render and using whitenoise to manage staticfiles. The site has a page that renders a user_manual.html and embedded images in an iframe within my page/navbar structure. This generally works fine.

Now the issue: I have an admin page that allow site admins to upload a new user manual as a MS Word .docx file to my media dir. The upload process does these things:

  • save the user_manual.docx to a django model FileField. (This is because I need the uploaded file to survive a server rebuild from docker image which does may not contain this newest version. On server startup, I also run these steps below.)
  • retrieve user_manual.html from database FileField and save into media folder.
  • run pandoc to convert to .rst file and extract images
  • run sphinx to build the user_manual.html and supporting files/structures.
  • copy the sphinx build folder to my static directory
  • call_command(‘collectstatic’, interactive=False) to run collectstatic

The above works fine. I can see the updated entry for user_manual.html in staticfiles.json and the new user_manual..html in the staticfiles dir. The new file is served when django restarts.

But, I want the new file to be served immediately and it is not. The browser console shows:
Failed to load resource: the server responded with a status of 404 ()
and browser shows: Not Found
The requested resource was not found on this server

If I restart the server, then the new user_manual.html is rendered. I infer that staticfiles.json is cached by either Django or whitenoise and the cache is not rebuilt when collectstatic is run.

Any suggestions on how can I get the new user manual.html to render without restarting the server?

(Separately, I attempted a couple of times to render this as an html string from the media folder, bypassing Django’s static file mechanism, but there were too many issues/complexities with css and images, etc.)

Many thanks in advance,
Charlie

Uploaded (or dynamically produced) files are handled by the “media” api. See the docs at Managing files | Django documentation | Django for the basics.

Your other option would be to allow your web server (e.g., nginx) to serve the static files. (Of course, I’m of the opinion that your web server should be handling all files.)

Thanks, Ken. I do use the django.core.files.storage features to handle the file uploads, then run pandoc and sphinx to generate the static user manual html. And it works fine…after a server restart.

I had hoped to get by without adding another layer of complexity by introducing nginx or some other separate static file server, if possible. It may not be possible.

As a workaround, we can just manually save the new user manual version in the media dir and include it in the next docker image build and deploy.