Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see error logs of Django views

I'm coding a small application with Django. But I can't see any error logs in the console when an error (e.g. Python syntax error, etc.) occurs in one of my views -no action at all.

How can I see the error logs of my views? Debugging like a blind is really annoying.

like image 589
Stephen T. Avatar asked Jan 23 '10 23:01

Stephen T.


People also ask

Where can I see Django logs?

The Django One-Click application employs Gunicorn and Upstart. Application level logging can be found in /var/log/upstart/gunicorn. log By default, Gunicorn logs to stderr and Upstart will collect output to stderr/stdout in /var/log/upstart/$JOB_NAME.

How do I use Django logs?

Make a basic logging call The way that Django logging is configured as part of the setup() function means that logging calls placed in settings.py may not work as expected, because logging will not be set up at that point. To explore logging, use a view function as suggested in the example below.

What is log file in Django?

It is basically writing the WARNING messages into a file called WARNING.log 'handlers': { 'file': { 'level': 'WARNING', 'class': 'logging.FileHandler', 'filename': BASE_DIR / 'warning.log', }, }, # A logger for WARNING which has a handler called 'file'.

What is server error 500 in Django?

When DEBUG is False , Django will email the users listed in the ADMINS setting whenever your code raises an unhandled exception and results in an internal server error (strictly speaking, for any response with an HTTP status code of 500 or greater). This gives the administrators immediate notification of any errors.


1 Answers

Django does not print any errors to the console by default. Instead it provides very helpful error pages that are displayed for any errors that occur in your views. Please check what your DEBUG setting is set to. In development this should be True which will give you the nice error pages for 404 and 500 errors.

The pretty error page will look like this: django error page
(source: linkaider.com)

I can also recommend the talk What the Heck Went Wrong? from DjangoCon2009 for some more information on basic debugging technics with django.

like image 74
Gregor Müllegger Avatar answered Oct 16 '22 23:10

Gregor Müllegger