0

I have deployed django website on debian 8 vps. The static files are held in static folder witch is at the same level as the app folder. The server can reach them on debian VPS. However the development version is located on Windows10 machine. The files are identical (cloned git repositories) but in the developement version tI get 404 on static/css/ when I try to reach my static files. From my setting.py file:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATIC_ROOT=os.path.join(BASE_DIR, 'static')

UPDATE:

I have moved my files to project_name/app_name/static (just as it is recommended in django documentation ) in both versions of the project. The effect is that now development server sees the files and deployed version does not (i.e. it displays raw html without any css styles) - so exactly the opposite to the previous situation. I am out of ideas. (maybe it has something to do with the fact that at certain point I did collectstatic so I have static folder in two locations???)

McCzajnik
  • 163
  • 1
  • 12
  • what is your debug mode ? – Exprator May 22 '17 at 06:40
  • debug is set to True – McCzajnik May 22 '17 at 10:16
  • I managed to make it working by doing collectstatic again which effectively copied static files from my app folder. also this answer here cleared it a little bit for me http://stackoverflow.com/questions/24199029/django-cannot-find-static-files-need-a-second-pair-of-eyes-im-going-crazy – McCzajnik May 22 '17 at 11:21

1 Answers1

3

In Django you must coexist with 2 settings.

When DEBUG = True, the enviroment serves staticfiles itself if the settings variable STATICFILES_DIRS where pointed to path. For me:

STATICFILES_DIRS= [os.path.join(PROJECT_ROOT, 'static').replace('\\','/'),]

When DEBUG = False the responsable for handling the staticfiles is Nginix/Apache.

In the project you shoud point the URL:

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

If you have a static folder in every app you can use:

python manage.py collectstatic

This grabs all your static files and put them on the same static folder (STATIC_ROOT)

Then your Ngnix/Apache also must to know where statifiles are stored

(An example using Ngnix):

server {
    access_log /pathto/log/acces.log;
    error_log  /pathto/log/error.log;
    server_name ******
    charset     utf-8;

    location /static {
        alias /path/to/your/static; <---- This Line
    }

    location / {
         uwsgi_pass django;
         include uwsgi_params;
         uwsgi_read_timeout 600;
     }
}

Always is good to take a look at documentation

Zartch
  • 945
  • 10
  • 25