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,