Log in

renamed static files after changing to prod.py settings

  • 5 Apr '16

This is what mentioned in page:
/static/spirit/stylesheets/styles.all.min.8d1f93f0c099.css
The correct path is (and available):
/static/spirit/stylesheets/styles.all.min.css

This issue was produced after SECRET_KEY setted.

remote: Executing 'python /var/lib/openshift/5700cf0b0c1e669bf7000025/app-root/runtime/repo//wsgi/myproject/manage.py collectstatic --noinput'
remote: Copying '/var/lib/openshift/5700cf0b0c1e669bf7000025/python/virtenv/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/contrib/admin/static/admin/css/base.css'
...
remote: Post-processed 'spirit/scripts/js/htmldiff/htmldiff.no-min.js' as 'spirit/scripts/js/htmldiff/htmldiff.no-min.1f53218275a0.js'
...

nitelyEsteban Castro Borsani
  • 5
  • 5 Apr '16

The correct path is (and available):
/static/spirit/stylesheets/styles.all.min.css

No, it's not. At least not for production environments. Check out the source code of this forum.

What's happening here, I believe, is that you can not write (persistent) files to the filesystem at runtime, ie: if you upload an image through the comment box it will be lost when restarting the app. This is something common in PaaS, but unlike Heroku (another PaaS), openshift does has a directory in which you can write files at runtime. Read the data point here.

The solution is to change the settings.py STATIC_ROOT and MEDIA_ROOT to the OPENSHIFT_DATA_DIR like this:

STATIC_ROOT = os.path.join(os.environ['OPENSHIFT_DATA_DIR'], 'staticfiles')
MEDIA_ROOT = os.path.join(os.environ['OPENSHIFT_DATA_DIR'], 'media')

Or to use an external service to store the files like AWS S3.

nitelyEsteban Castro Borsani
  • 2
  • 5 Apr '16

Oh, you also got to change the Whoosh search index path:

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
        'PATH': os.path.join(os.environ['OPENSHIFT_DATA_DIR'], 'whoosh_index'),
    },
}

And manually create the whoosh_index folder, I don't remember if haystack or Whoosh does it for you or just fails.

Same if you use sqlite, altough sqlite is not good for production except if you have really tiny community. Openshift provides postgresql for free, I've read.

# Not recommended for production, use postgresql instead.
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(os.environ['OPENSHIFT_DATA_DIR'], 'db.sqlite3'),
    }
}
  • 7 Apr '16

Solved!
I looked at this and changed STATIC_ROOT = os.path.join(BASE_DIR, 'static') to STATIC_ROOT = os.path.join(WSGI_DIR, 'static')
Now static files are collecting in ./wsgi/static instead of ./wsgi/myproject/static
But I'll should use OPENSHIFT_DATA_DIR for MEDIA_ROOT

Reply