1

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

Community
  • 1
  • 1
general03
  • 855
  • 1
  • 10
  • 33

3 Answers3

0

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
dmitryro
  • 3,463
  • 2
  • 20
  • 28
0

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()
dmitryro
  • 3,463
  • 2
  • 20
  • 28
  • My **wsgi.py is good**. I haven't to use `./manage.py collectstatic` if my static folder is already full ? – general03 Jun 16 '16 at 20:23
  • You HAVE to use it as the static is where files are TAKEN, not where they are initially placed. The philosophy of Django to collect files from all over the known places in your OS and place them into static. – dmitryro Jun 16 '16 at 20:25
  • STATICFILES_FINDERS = [ 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', ] # this is used by Django to check static files and set them in STATIC_ROOT – dmitryro Jun 16 '16 at 20:27
  • collectstatic makes sure your static files are up to date and are reachable by Django. – dmitryro Jun 16 '16 at 20:29
  • Thanks @dmitryro but even if I launch the command I can't reach my static files – general03 Jun 16 '16 at 20:45
  • Try specifying it explicitly as STATICFILES_DIRS = '/your_location_from_root/static' – dmitryro Jun 16 '16 at 20:47
  • I put the absolute path in STATICFILES_DIRS and STATIC_ROOT without success – general03 Jun 16 '16 at 20:59
  • I have to access to my static file by `http://yourdomain.com/static/...` ? – general03 Jun 17 '16 at 06:58
0

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

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
general03
  • 855
  • 1
  • 10
  • 33