Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The accepted answer didn't work for me. I use Selenium for testing, and setting <code>@override_settings(DEBUG=True)</code> makes the test browser always display <code>404</code> error on every page. And <code>DEBUG=False</code> does not show exception tracebacks. So I found a workaround.</p> <p>The idea is to emulate <code>DEBUG=True</code> behaviour, using custom <code>500</code> handler and built-in django <code>500</code> error handler. </p> <ol> <li><p>Add this to <em>myapp.views:</em></p> <pre><code>import sys from django import http from django.views.debug import ExceptionReporter def show_server_error(request): """ 500 error handler to show Django default 500 template with nice error information and traceback. Useful in testing, if you can't set DEBUG=True. Templates: `500.html` Context: sys.exc_info() results """ exc_type, exc_value, exc_traceback = sys.exc_info() error = ExceptionReporter(request, exc_type, exc_value, exc_traceback) return http.HttpResponseServerError(error.get_traceback_html()) </code></pre></li> <li><p><em>urls.py:</em></p> <pre><code>from django.conf import settings if settings.TESTING_MODE: # enable this handler only for testing, # so that if DEBUG=False and we're not testing, # the default handler is used handler500 = 'myapp.views.show_server_error' </code></pre></li> <li><p><em>settings.py:</em></p> <pre><code># detect testing mode import sys TESTING_MODE = 'test' in sys.argv </code></pre></li> </ol> <p>Now if any of your Selenium tests encounters 500 error, you'll see a nice error page with traceback and everything. If you run a normal non-testing environment, default 500 handler is used.</p> <p>Inspired by: </p> <ul> <li><a href="https://stackoverflow.com/questions/12924746/where-in-django-is-the-default-500-traceback-rendered-so-that-i-can-use-it-to-cr">Where in django is the default 500 traceback rendered so that I can use it to create my own logs?</a></li> <li><a href="https://stackoverflow.com/questions/4088253/django-how-to-detect-test-environment">django - how to detect test environment</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload