Forums

Trying to update static files on existing django project...

I have a portfolio site that I'm updating. There were 3 projects existing within the app before I deployed at pyanywhere. I'm looking to add a 4th post deployment (a site update if you will). I decided to add the project via the admin site. Here are the steps taken thus far.

  1. Added jpg to staticfiles/ directory thru pyanywhere (path: home/user/appname/staticfiles)
  2. Added the project to the DB using the admin site and selected the jpg loaded in step 1, tested the site and all project info loads except the jpg for the new project, all old projects are good
  3. Added the new jpg to static/ directory inside the app (this was the orginial static directory before deployment and is the location of all the working images when the site loads-path: home/user/appname/app/static)
  4. Ran collectstatic and error was given for not having set STATIC_ROOT in settings.py
  5. Set STATIC_ROOT as directory to staticfiles (e.g. home/user/appname/staticfiles) and it did not fix the issue
  6. Set static root to static/ directory in app (e.g. home/user/appname/app/static) and did not fix the issue
  7. Checked developer view of website and saw that all static files that were loaded had a simple url of 'static/img/some.jpg' while the newly loaded img has a url of 'static/home/user/appname/app/static/....' and no matter how I updated STATIC_URL or STATIC_ROOT nothing would change and I cannot get the new image to load. Also, even if I select an old image through the admin site (so, one that was already working for another project on the page) it won't load that image for the newly added project.

What am I missing here?

The STATIC_ROOT setting is not a per-app thing, it's for the website as a whole. When you run the collectstatic management command, it collects all of the static assets from the per-app directories (like /home/user/appname/staticfiles) and puts them into one global location.

So if you set it to the global location, which would normally look like this:

STATIC_ROOT = BASE_DIR / "static"

...and then run the collectstatic management command, it should all work fine.