[Fixed]-Static files not showing up on live server

1👍

To avoid hardcoding, you can set STATIC_ROOT this way:

STATIC_ROOT = os.path.join (os.path.dirname(BASE_DIR), "staticfiles", "static")

So your static files for production will be in a directory near your project’s folder. Moreover you can do the same stuff with MEDIA_ROOT.

MEDIA_ROOT = os.path.join (os.path.dirname(BASE_DIR), "staticfiles", "media")

0👍

Thanks Hedde van der Heide for the solution


Setting STATIC_ROOT to the actual location of the files worked

e.g.

STATIC_ROOT = “/var/www/example.com/static/”

https://docs.djangoproject.com/en/1.8/howto/static-files/#deployment

👤Franco

0👍

Do render a static file in your live website, you have to add the below code in your setting file.

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

# Static files (CSS, JavaScript, Images)
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'

# Extra places for collect static to find static files.
STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, 'static'),
)

Also add this in your INSTALLED APPS,

INSTALLED_APPS = 
['django.contrib.staticfiles',]

Leave a comment