Static files on OpenShift Django

django, openshift, python

Solution

1) You've mixed up STATIC_URL and STATIC_ROOT variables.

STATIC_ROOT: Needs to point to the directory where you want your static files to be collected. In this case, it seems it is PROJECT_PATH + '/static/'. Make sure this directory is correct.

STATIC_URL: The url your static files are accessed. /static/ is correct.

Remove the STATICFILES_DIRS variable. It can't be the same as STATIC_ROOT because first tells Django where to FIND static files and second tells Django where to STORE static files when they are collected.

2) If you are working with Openshift, as @timo.rieber points out, you will need an action_hook for deploy to tell it to collect your static files.

3) Your static_root folder can't be anywhere in your project because Openshift webserver won't find it. It should be under yourproject/wsgi/static <--- (Thus, this will be the STATIC_ROOT variable value).

As I already answered you in another question, starting a new project from scratch for Openshift is painful. I've wrote a post about creating a new project to make it work with Openshift and you can also visit the commit referenced there which will redirect you to a basic Openshift project which works. You can also download basic project from Openshift repo but it follows an old (but still working) project structure. You can now use a simpler project structure for python apps

Problem

I'm having issues serving up static files - i.e. style sheets and images required from my html pages. I cannot seem to fathom why these static images are not being found. Here is what I have in my `settings.py` ``` STATIC_URL = PROJECT_PATH + '/static/' # Additional locations of static files STATICFILES_DIRS = (PROJECT_PATH + "/static/",) STATIC_ROOT = "/static/" # List of finder classes that know how to find static files in # various locations. STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', 'django.contrib.staticfiles.finders.DefaultStorageFinder', ) ``` I'm getting a 404 error, when I tail into the log. But I cannot figure out where or debug or figure out where OpenShift is looking for these images. I've tried using `STATIC_URL = '/static/'` but that doesn't work either.

Original source

Related problems