Search code examples
django-1.11

Django 1.11 (Python 3.+) doesn't work styles, when I make DEBUG=False


When I try it gives 404 error view, my styles doesn't work. I tried to create custom 404 view but it also doesn't work.

Here is my code.

settings.py

   DEBUG = False
   TEMPLATE_DEBUG = DEBUG

   ALLOWED_HOSTS = ['*']

   TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'ran_app/templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'debug': DEBUG,
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

STATIC_URL = '/static/'

I have 404.html page too in templates.

Here is the browser error.

Failed to load resource: the server responded with a status of 404 (Not Found)


Solution

  • When there is DEBUG = False default Django package will not serve any static files from your server . You have to use a nginx like tool to serve your files and it is a condition like production server.