bayman
bayman

Reputation: 1719

Static files aren't loading after changing STATIC_ROOT and STATICFILES_DIRS in django

I was following a tutorial on setting STATIC_ROOT using a CDN for my satic files but I've decide I'd like to serve my static files on the same server where my django app is served. I tried changing to the new settings below and I ran manage.py collectstatic and now the static files aren't loading. What am I doing wrong? This is w/ django 1.9

new settings not working:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

old settings working:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn")
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
    ]
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "media_cdn")

Upvotes: 0

Views: 1562

Answers (1)

fizzyh2o
fizzyh2o

Reputation: 1319

Where are you keeping your static files?

If you are keeping them in BASE_DIR/static then it is important to include the sameSTATICFILES_DIRS` as you have in the second settings file.

If you having your static files spread throughout your different apps then you want to make sure that django.contrib.staticfiles.finders.AppDirectoriesFinder is added to your STATICFILES_FINDERS.

The point of collectstatic is to get static files from all your various apps (admin,polls,ect.) and move them to your static root for serving. You also need to make sure that your STATIC_ROOT is being served.

It's also probably not a good idea to have you STATIC_ROOT pointing to somewhere inside your BASE_DIR - usually this will not be served statically by your web server.

Upvotes: 1

Related Questions