On Nov 8, 5:39 am, project2501 <[EMAIL PROTECTED]> wrote:
> Hi,
>   I got Django to work behind Apache2 with mod_python, but had some
> questions for the experts.
>
> 1) Is there an easy way to log stdout without re-writing all my output
> statements? What about python logging?

Anything sent to stdout in mod_python will end up in the Apache error
logs, at least eventually. The problem is that it is buffered and it
requires explicit flushing.

To avoid having to modify code, you may be better off using mod_wsgi.
In mod_wsgi output to stdout will actually generate an error by
default, because portable WSGI applications should not output to
stdout and some WSGI hosting mechanisms use stdin/stdout. One can
disable this restriction in mod_wsgi through a configuration directive
or by reassigning sys.stdout to be sys.stderr.

In general, outputing debug to stdout in web applications is a bad
idea. You should instead output them to stderr instead.

For more information see:

http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Writing_To_Standard_Output

> 2) Is there a good way in Django to put startup code when deployed in
> Apache that only gets run once per server restart? I build some
> indexes that are used by my Django apps but it only needs to be done
> at initialize time once.

You can put code in settings file. Do note however that this will be
executed once per process created by Apache. Since Apache is
multiprocess this can therefore happen many times in life of Apache
instance. Apache can also recycle processes within lifetime of Apache
instance.

With mod_wsgi, things are perhaps again more flexible as you can put
startup code in WSGI script file rather than having to put it in
settings file. Also, mod_wsgi allows you using mod_wsgi daemon mode to
delegate application to single daemon process if having initialisation
done more than once is a problem.

More information on mod_wsgi and Django at:

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

Graham
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to