1
votes

I can't found my static files like css, js and picture. I get 404 error page.

In my settings django I have

STATIC_ROOT = '/var/lib/openshift/*id*/app-root/repo/*project*/*app*' 
STATIC_URL = '/static/'

and my filesystem are

 - project
   - app
     - wsgi.py
     - static # I also tried to move this folder in wsgi folder
       - css
         - base.css
     - ... 

I tried to move the static folder in wsgi folder created before. I also tried to move my static folder or wsgi folder in data folder of openshift without success.

I follow few help posts from Stackoverflow without found my answer

Can you help me to configure my static folder ?

Thanks

3
Can I write something in .htaccess ? - general03
What is the apache configuration for static folder ? This location is fixed in apache ? - general03

3 Answers

0
votes

in your settings.py make sure you have:

import os
import sys

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


STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static_files'),
                   )  # create static_files dir and place there your static  
                      # files to be collected, as static is the destination
                      # directory of your local and other Django 
                      # modules static files 

STATIC_ROOT = os.path.join(BASE_DIR, 'static', )
STATIC_URL = 'http://yourdomain.com/static/'

once done run

 ./manage.py collectstatic 

make sure you have tree like

 yourproject+
            |
            +-yourproject
            |           | 
            |           +urls.py  
            |           |
            |           +settings.py
            |           |
            |           +wsgi.py
            |
            +manage.py
            |
            +static_files
            |
            +static
0
votes

You also need to make sure your manage.py is modified to be:

import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourproject.settings")

    from django.core.management import execute_from_command_line  

    execute_from_command_line(sys.argv)

and wsgi.py to be

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourproject.settings")

application = get_wsgi_application()
0
votes

In the wsgi.py I have to have sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'])) os.environ['DJANGO_SETTINGS_MODULE' ] = 'project.settings.app' and in my settings.py STATIC_ROOT = os.path.join(os.getenv('OPENSHIFT_REPO_DIR'), 'wsgi/static', ) STATIC_URL = '/static/' And the filesystem of my website repo project ... wsgi static wsgi.py