Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Django code on mod_wsgi (how to access ['wsgi.errors'])

I'm getting started with developing Django code on a server, running on top of Apache/mod_wsgi.

I'm looking to understand a few things:

  1. What techniques are normally used to debug applications running on the server?

  2. Specifically, I'm trying to just use "print" debugging for now. But I can't seem to get print statements to work. I'm printing to stderr, but I'm not sure which log file I should be looking at. According to this, I should be using environ['wsgi.errors'], but how do I access that from my Django code?

Thanks!

EDIT: By the way, adding the line print >> sys.stderr, 'message ...' not only doesn't seem to print to any log file, it causes parts of my application to simply not load.

like image 633
Edan Maor Avatar asked Jan 27 '11 07:01

Edan Maor


People also ask

How does WSGI work in Django?

It's used both by Django's development server and in production WSGI deployments. WSGI servers obtain the path to the application callable from their configuration. Django's built-in server, namely the runserver command, reads it from the WSGI_APPLICATION setting. By default, it's set to <project_name>.

What is WSGI script alias?

The WSGIScriptAlias directive behaves in the same manner as the Alias directive, except that it additionally marks the target directory as containing WSGI scripts, or marks the specific file-path as a script, that should be processed by mod_wsgi's wsgi-script handler.

What is WSGI config?

WSGI is a specification of a generic API for mapping between an underlying web server and a Python web application.


1 Answers

  1. Try using the django debug toolbar. It can help a great deal with debugging when you can't actually use a debugger.

    Really though, debugging should be done on your development machine. I have yet to see a code issue in production with django that wasn't also occurring on my dev box.

  2. You usually can't print in mod_wsgi. Use the logging module instead. That's really what you want, and the debug toolbar will show you log statements in the page, so you don't even have to look at the file.

like image 57
Seth Avatar answered Oct 16 '22 18:10

Seth