1

I have a project that has been running just fine for about 6 months. Static files have been working perfectly, and everything is great. I have my static files located in a folder as so:

/var/www/html/static/

In my settings.py file, I have the static section setup like so:

STATICFILES_DIRS = (
     os.path.join(BASE_DIR, "static"),
     '/var/www/html/static/',
     )

This has been working just fine.

However, I now want to move the static folder to a different location. Specifically, I want to move it inside the main project directory. My project is located at /var/www/html/shq/ so I want to have my static directory located at /var/www/html/shq/static/. I moved the folder, then updated my settings.py file to look like this:

STATICFILES_DIRS = (
     os.path.join(BASE_DIR, "static"),
     '/var/www/html/shq/static/',
     )

However, it didn't work. The Django project is still referencing the old location.

What am I missing here? Why isn't the Django project using the new location of /var/www/html/shq/static/?

EDIT

This is what the tail end of my settings.py file looks like:

119 STATICFILES_FINDERS = [
120   'django.contrib.staticfiles.finders.FileSystemFinder',
121   'django.contrib.staticfiles.finders.AppDirectoriesFinder',
122 ]
123
124 STATIC_URL = '/static/'
125 STATIC_ROOT = '/var/www/html/collected_static/'
126 MEDIA_URL = '/media/'
127 MEDIA_ROOT = '/var/www/html/shq/media/'
128 STATICFILES_DIRS = [
129     os.path.join(BASE_DIR, "static"),
130     '/var/www/html/shq/static/',
131     ]
Garfonzo
  • 3,876
  • 6
  • 43
  • 78

2 Answers2

0

You might try doing something like this. I think it returns the list of directories that django looks for to find static files. Might help debugging.

from django.contrib.staticfiles import finders
from pprint import pprint
pprint(finders.find("", all=True))

Also, I may not be fully understanding your scenario, but you might confirm that the STATIC_ROOT is set to the location where you want to serve your static files (where your webserver will serve the files). The STATIC_DIRS setting tells collectstatic where to find static files, but the STATIC_ROOT is where collectstatic will actually place the files.

Joe J
  • 9,985
  • 16
  • 68
  • 100
  • `STATIC_ROOT` is set to a separate directory so that static files are stored there for production (and when `DEBUG=False`). I entered that script you posted into a `python` editor, but it complains that the `STATICFILES_FINDERS` isn't set, even though it is (I have the two finders listed). Not sure why this is always so frustratingly challenging. -- Edit -- I also updated the post to show more of my `settings.py` file – Garfonzo Jun 15 '16 at 02:33
0

I figured it out. Not surprisingly, it was an easy fix once I figured it out.

It had nothing to do with my Django settings and everything to do with Apache.

Original

Alias /static/ /var/www/html/static/

So no matter what I did in my Django settings.py file, Apache was overriding that to send /static/ requested to the wrong directory.

New Apache Setting

Alias /static/ /var/www/html/shq/static/

Now the proper static files are being referenced. Hopefully this helps someone else in the future :)

Garfonzo
  • 3,876
  • 6
  • 43
  • 78