Forums

Static Files Not loading

I can't get the static files to load on my page and neither on the admin section. (404 not found on the chrome console)

I have already checked questions from other user and possible solutions but I can't get through it from suggestions made to other users.

On my settings.py I have (works fine on local) :

INSTALLED_APPS = (
(...)
  'django.contrib.staticfiles',
)

import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
MAIN_DIR = os.path.dirname(os.path.dirname(__file__))

(...)

 STATIC_URL = '/static/'


STATICFILES_DIRS = (
    os.path.join(MAIN_DIR, 'static'),
)

And for the admin I've tried adding:

STATIC_ROOT = '/home/varveler/.virtualenvs/env/lib/python2.7/site-packages/django/contrib/admin/static/admin'

But its not working.

Also in 'web' tab i have the path for statics: /home/varveler/tdmx/tdmxa/static/

I am barely new to coding, am I missing something? How does specify your path-to-statics on the web tab works? does it override settings.py? Regards.

django.contrib.staticfiles is what Django recommends for development, we provide the static files entries on the web app tab so you don't need to use it.

STATIC_ROOT is not what you think it is if you're pointing it to the admin static folder. STATIC_ROOT is where Django collects static files so they can be served by the web server instead of Django (it's faster and more secure to do it that way).

So I think you want to remove the staticfiles app from Django, set static root to /home/varveler/tdmx/tdmxa/static/, set the static file entry on the webapp page to point /static to /home/varveler/tdmx/tdmxa/static/ and run the collectstatic management command.

There are docs here and here

Thanks Glenn, now its working.

Great! Thanks for confirming that.

Hi Glenn, This is the path for my static files "/home/Aswini02/myweb/blog/static/" and I have given STATIC_ROOT='/home/Aswini02/myweb/blog/static/'. But my static files are not getting loaded. Please provide me a solution.

Thanks, Aswini

Have you worked through the docs? http://help.pythonanywhere.com/pages/StaticFiles/ and http://help.pythonanywhere.com/pages/DebuggingStaticFiles/

Thanks a lot glenn.

For all those who are still facing errors and are unable to load their static files.

Just go to the main folder, and run ls -a. There you will see some folder called static. Similarly, inside it you will find a folder called admin.

But we do not want that static folder to be referenced by the web-app. So, go to the Web tab from your Dashboard. At the bottom, you will find the static and media file, there you just need to add the folder you want it to reference. Just edit the path. Reload the app. And you're done.

This is what I have created.

[edit by admin: formatting]