Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does DEBUG=False setting make my django Static Files Access fail?

Am building an app using Django as my workhorse. All has been well so far - specified db settings, configured static directories, urls, views etc. But trouble started sneaking in the moment I wanted to render my own beautiful and custom 404.html and 500.html pages.

I read the docs on custom error handling, and set necessary configurations in UrlsConf, created corresponding views and added the 404.html and the 500.html to my app's template directory (specified in the settings.py too).

But the docs say you can actually view custom error views until Debug is Off, so I did turn it off to test my stuff, and that's when stuff goes berserk!

Not only do I fail to view the custom 404.html (actually, it loads, but because my error pages each contain a graphic error message -as some nice image), the source of the error page loads, but nothing else loads! Not even linked CSS or Javascript!

Generally, once I set DEBUG = False, all views will load, but any linked content (CSS, Javascript, Images, etc) wont load! What's happening? Is there something am missing, concerning static files and the DEBUG setting?

like image 656
JWL Avatar asked Apr 29 '11 19:04

JWL


People also ask

What does debug false do Django?

Open your settings.py file (or settings_local.py ) and set DEBUG = False (just add that line if necessary). Turning off the Django debug mode will: Suppress the verbose Django error messages in favor of a standard 404 or 500 error page. You will now find Django error messages printed in your arches.

How do I change debug false?

To disable debug mode, set DEBUG = False in your Django settings file.

What is debug false?

The DEBUG=True , if there is error, page will show details of error. if DEBUG=False , the ALLOWED_HOSTS of settings.py will work, you should take carefully to set it. the media and static will not provide access for DEBUG=False , you have to provide them with the help of webserver, like Nginx or Apache .

What does Django debug true do?

The debug mode (DEBUG=True) is turned on by default in the Django framework. It provides a detailed traceback with the local variables to find out the error with the line numbers. The error can be triggered from the view page by setting the value of assert to False in the view file.


2 Answers

If you still need to server static locally (e.g. for testing without debug) you can run devserver in insecure mode:

manage.py runserver --insecure 
like image 82
Dmitry Shevchenko Avatar answered Sep 23 '22 20:09

Dmitry Shevchenko


With debug turned off Django won't handle static files for you any more - your production web server (Apache or something) should take care of that.

like image 41
Marek Sapota Avatar answered Sep 23 '22 20:09

Marek Sapota