0

I have extensively searched for a solution to my problem; however, due to the lack of success I decided to post a question.

In short: I have created an OpenShift app/build based on this repo (in combination with a DIY 0.1 cartridge):

https://github.com/ehazlett/openshift-diy-py27-django

The (apparently quite common) problem I have is that I can not get access to static files working; I have tried a lot.

These are a few things of all I have tried so far (and I am assuming that the wsgi for this build is /app/ (?)):

  • STATIC_ROOT
    • I tried to set this to pretty much all possible places in my repo while placing a static folder with the corresponding static files in there, e.g.
      • /static
      • /app/static
      • /app/app/static
      • etc.
  • STATIC_URL
    • I kept this set to '/static/' as this is just the URL prefix if I'm not completely wrong
  • STATICFILES_DIRS
    • set this to the absolute path on the file system, there shouldn't be much that could be wrong with that.
  • .htaccess tried a few things with .htaccess rewrites as well but mildly in the wild as I am not perfectly sure how communication flow between Django and Apache works/how Django passes static requests on to Apache and where on the file system/in the repo Apache's root dir is (?)

I can give more info if needed but that's the essential so far.

It should be noted that this seems to be a unique case with this build as I don't have problems when i create an app based on the fully supported Python26/Django cartridge.

Any suggestions whatsoever would be greatly appreciated..!

Cheers~

bossi
  • 103
  • 3

2 Answers2

0

This article "Serving Django Static Assets on OpenShift", seems to suggest a solution.

larsks
  • 43,623
  • 14
  • 121
  • 180
-1

Static files should be served directly by Apache, not by Django. The process is as follows (assuming your codebase is /srv/code/project):

  • Place your static files in /srv/code/project/app/static/ (where app is listed in INSTALLED_APPS)
  • If you need static files not related to an app (or common to many), define a directory in STATICFILES_DIRS (usually within your codebase, e.g. /srv/code/project/static/) and place the files there.
  • Define a STATIC_ROOT outside your codebase, e.g. /srv/www/example.com/static/. This is going to act as a cache of all static files.
  • Whenever deploying a new version of the project, run python manage.py collectstatic. This will go through all the static directories and copy the files to STATIC_ROOT.
  • Configure Apache to serve all requests under /static/ from the STATIC_ROOT.
mgorven
  • 30,615
  • 7
  • 79
  • 122
  • Great, thanks for your reply; however, that's pretty much as far as I had already gotten and your last step (configuring Apache to serve from the directory I define in `STATIC_ROOT`) is where I get stuck on OpenShift as I can't find a way to configure Apache (centrally or on sub-branches of the FS through `.htaccess`). If there still is a way I'd be very curious. (++ if I were able to vote yet!) – bossi Mar 05 '13 at 13:01
  • This answer doesn't seem to address OpenShift at all. – larsks Sep 05 '13 at 15:24