Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: logging template errors

When I make an error in a django template {{placeholder}}, I get no error, just blank space in the output where I was expecting content. Is there a way to see something in my logs when this occurs, preferably using logging.warning or logging.error?

like image 933
Paul Biggar Avatar asked Jan 22 '10 04:01

Paul Biggar


People also ask

How do you disable verbose error handling and logging in Django?

Disabling logging configuration If you don't want to configure logging at all (or you want to manually configure logging using your own approach), you can set LOGGING_CONFIG to None . This will disable the configuration process for Django's default logging.

How do I enable logging in Django?

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.

Where are Django logs stored?

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 debug an app in Django?

Debug the Containerized Django AppSet a breakpoint somewhere in your code. Then in VS Code open the "Run" view again and make sure the Run Django configuration that we previously created is selected. Click the play button to start the debugging session.


2 Answers

Yes, there is. Just add in your development settings.py:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        'django.template': {
            'handlers': ['console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'),
        },
    },
}

As roboslone stated, Django 1.9 did introduce it. The snippet is very similar to the second of Configuring logging examples in Django docs.

like image 149
maciek Avatar answered Oct 09 '22 10:10

maciek


The only thing Django provides for handling unknown context variables in TEMPLATE_STRING_IF_INVALID. You're going to have to do some deeper hacking of the template engine if you want better than that.

like image 23
Ignacio Vazquez-Abrams Avatar answered Oct 09 '22 10:10

Ignacio Vazquez-Abrams