dekarz dekarz - 2 years ago 142
Python Question

Django static files (404 not found) - Openshift

I'm trying to run my very first project using Python/Django on Openshift and have problem with loading my static files.

I've read the multiple times I have been breaking my head over this for a full day but can't figure out the problem.

I'm running a developer server:

python runserver

STATIC_URL = '/static/'

if 'OPENSHIFT_REPO_DIR' in os.environ:
STATIC_ROOT = os.path.join(os.environ.get('OPENSHIFT_REPO_DIR'), 'wsgi', 'static')
STATIC_ROOT = os.path.join(WSGI_DIR, 'static')


{% load static %}
<a href=""><img src="{% static "logo2.png" %}"></a>

from django.conf.urls import include, url
from django.contrib import admin
from django.views.generic import RedirectView
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = [
url(r'^$', RedirectView.as_view(url='/index/')),
url(r'^index/', include('index.urls')),
url(r'^polls/', include('polls.urls')),
url(r'^admin/', include(,

urlpatterns += staticfiles_urlpatterns()

The weirdest thing is that after pushing my app to openshift everything is working just fine but on localhost sth goes wrong.

Make long story short:

  • - Not found

  • - Yeah, I see the image

I hope it's clear and my problem is as stupid as I imagine.

Django 1.8, OS Windows


I've deleted the 'django.contrib.staticfiles' from INSTALLED_APPS and add to the this peace of code:

if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Gil Gil
Answer Source

Are you in development mode? If yes and if you don't have django.contrib.staticfiles in INSTALLED_APPS, you need to add this to

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Explained here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download