<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Chirashi Security &#187; Django</title>
	<atom:link href="http://chirashi.zenconsult.net/category/django/feed/" rel="self" type="application/rss+xml" />
	<link>http://chirashi.zenconsult.net</link>
	<description>A blog with scattered thoughts on security</description>
	<lastBuildDate>Sun, 16 Oct 2011 17:26:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Sending messages to the Apache Error.log file when using Django</title>
		<link>http://chirashi.zenconsult.net/2009/05/sending-messages-to-the-apache-errorlog-file-when-using-django/</link>
		<comments>http://chirashi.zenconsult.net/2009/05/sending-messages-to-the-apache-errorlog-file-when-using-django/#comments</comments>
		<pubDate>Sun, 31 May 2009 08:27:57 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[HOWTO]]></category>

		<guid isPermaLink="false">http://chirashi.zensay.com/?p=23</guid>
		<description><![CDATA[Solves the problem of "sys.stdout access restricted by mod_wsgi"]]></description>
			<content:encoded><![CDATA[<p>I spent a considerable amount of time reading documentation that told me how to send errors to the Apache log filewhen you use mod_wsgi. I read documentation on how to integrate mod_wsgi with Apache and Django.  All of this was fine, but when I was trying to get it to work with my Django 1.0.2 installation and Apache2 running mod_wsgi, I was constantly greeted by lots of errors.  One in particular was &#8220;sys.stdout access restricted by mod_wsgi&#8221;.  The documents online didn&#8217;t help at all.</p>
<p>Finally, after looking into the django.core.handlers.wsgi module, I figured out how to send errors to the wsgi.errors setting and subsequently send errors to your Apache2 Error.log file.</p>
<p>I started off with my views.py as follows:</p>
<pre lang="PYTHON" line="1">from django.http import HttpResponse
from django.shortcuts import render_to_response, get_object_or_404
from myapp.models import F

def index(request):
    c = {}
    return render_to_response('myapp/index.html',c)

def detail(request, name):
    n = F.objects.get(name=name)
    c = {'name': n.fof}
    return render_to_response('myapp/detail.html',c)</pre>
<p>If I needed to write to the Error.log file, I would have to change the code thusly:</p>
<pre lang="PYTHON" line="1">from django.http import HttpResponse
from django.shortcuts import render_to_response, get_object_or_404
from myapp.models import F

def index(request):
    c = {}
    print >> request.environ['wsgi.errors'],"Teh Errorist!"
    return render_to_response('myapp/index.html',c)

def detail(request, name):
    n = F.objects.get(name=name)
    c = {'name': n.fof}
    return render_to_response('myapp/detail.html',c)</pre>
<p>The change is in line 7</p>
<p>I felt really stupid, because the solution was so straightforward.  I felt even more stupid that I couldn&#8217;t find any documentation out there.  Either way, I&#8217;m pleased that my app works, and in case someone else out there is searching for how to achieve this, then the above is how to do it.</p>
]]></content:encoded>
			<wfw:commentRss>http://chirashi.zenconsult.net/2009/05/sending-messages-to-the-apache-errorlog-file-when-using-django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

