0

So I followed this tutorial: https://github.com/rancavil/django-openshift-quickstart/wiki/Tutorial-How-create-an-application-with-Django-1.6-on-Openshift

and I tried to add a static image to the default home.html page and it just won't find it.

HTML:

{% load static %}
<html>
    <head>

    </head>
    <body>
        <img src="{% static 'Logo_Trans.png' %}">
        <div class="left"></div>
        <div class="right">
            <p>is coming soon</p>
        </div>
    </body>
</html>

All other files are as listed in the repo given.

Tony Li
  • 137
  • 1
  • 10

2 Answers2

1

I've found the problem. The static files were serving properly when deployed but not when in debug mode. To fix this just add the STATICFILES_DIR variable in settings.py

Find:

if ON_OPENSHIFT:
     DEBUG = False
else:
     DEBUG = True

Add:

if ON_OPENSHIFT:
     DEBUG = False
else:
     DEBUG = True
     STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),
                            '/var/www/static/',)

Openshift is a very good service but definitely needs to update their docs/examples for django. Their sample program still runs django 1.4. Hope this helps anyone else that runs into this problem.

Tony Li
  • 137
  • 1
  • 10
1

you can read the answer for this question Django cannot find static files. Need a second pair of eyes, I'm going crazy. Hope it will help you to understand static files. Static files in Django are always a bit painful.

Btw, as I explain in the last comment, I recommend you to create an app called common within a static folder inside it to place static content that is not application specific. Static application specific files should be placed inside the static folder within your app. This way, you can forget about defining the STATICFILES_DIRS variable and it will always work in DEBUG mode.

After that, ofc, define STATIC_ROOT and when you want to work in deploy mode, do the collectstatic command and it will also work.

After dealing hundreds of times with issues like this, I've found this is the best approach.

Community
  • 1
  • 1
argaen
  • 4,145
  • 24
  • 28