-3

i'm having some problem with my django website. Everything runs good but when i switch the debug mode to false, the admin panel has no more style(css). Can someone explain why? Sorry if the question is so short.

this is my main urls.py file:

from django.conf.urls.defaults import patterns, url, include, handler500, handler404
from django.conf import settings 
from django.contrib import admin
admin.autodiscover()


urlpatterns = patterns('',
    url(r'^aste/', include('aste.urls',namespace="aste")),
    url(r'^', include('utenti.urls',namespace="utenti")),
    url(r'^forum/', include('forum.urls',namespace="forum")),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
            'document_root': settings.MEDIA_ROOT,
        }),    
)
  • Are you running your application locally? If so have you set up special urls to use the development server to serve your static files during development? – Timmy O'Mahony Nov 03 '14 at 17:56
  • yes i'm running it locally, yes i set some urls for the admin, and everything it's ok with debug mode = True, but if it is false i get the problem. I've more than one urls file, but now i'll post the main one, with the admin urls. – Alberto Lancellotti Nov 03 '14 at 17:58
  • possible duplicate of [Why does DEBUG=False setting make my django Static Files Access fail?](http://stackoverflow.com/questions/5836674/why-does-debug-false-setting-make-my-django-static-files-access-fail) – Daniel Rucci Nov 03 '14 at 18:05

1 Answers1

2

When debug mode is False Django won't serve static files (by default).

This is mentioned here https://docs.djangoproject.com/en/dev/howto/static-files/#managing-static-files-css-images

You can pass the --insecure flag when running your server E.G ./manage.py runserver --insecure to change this behavior but you should avoid this in production and read the static-files documentation on how to have a web server serve this content instead of Django.

Daniel Rucci
  • 2,822
  • 2
  • 32
  • 42