<?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>tech stuff &#187; wsgi</title>
	<atom:link href="http://codytaylor.org/tag/wsgi/feed" rel="self" type="application/rss+xml" />
	<link>http://codytaylor.org</link>
	<description>From Cody Taylor.</description>
	<lastBuildDate>Sun, 30 Oct 2011 04:15:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Django Quick Install With WSGI</title>
		<link>http://codytaylor.org/2009/05/django-quick-install-with-wsgi.html</link>
		<comments>http://codytaylor.org/2009/05/django-quick-install-with-wsgi.html#comments</comments>
		<pubDate>Sat, 30 May 2009 20:15:53 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[wsgi]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14059</guid>
		<description><![CDATA[Django is a high level python web framework that I've been hearing a lot about lately..]]></description>
			<content:encoded><![CDATA[<p>Django is a high level python web framework that I&#8217;ve been hearing a lot about lately. I decided to try it out this weekend.<br />
It took a little reading to get up and running so I documented the steps I took so others can get up and running a little more quickly.</p>
<p><span style="color: #888888;">sudo apt-get install django<br />
django-admin &#8211;version </span></p>
<p>Create the appropriate directories and start the django project.</p>
<p>For no real reason I decided to put my new projects in /var/django.<br />
<span style="color: #888888;">sudo mkdir /var/django<br />
sudo chmod 755 /var/django<br />
cd /var/django<br />
django-admin startproject mysite<br />
cd mysite<br />
mkdir apache</span></p>
<p>It seems that mod-wsgi is the best way to serve up python web apps due to mod_python being a little outdated. Note that django does come with a built in webserver that is really easy to get going. So if you&#8217;re just planning on evaluating the framework and not actually do any production aplications then that would be the way to go. mod_wsgi is an Apache module which can be used to host Python applications.</p>
<p>Install the module:<br />
<span style="color: #888888;">sudo apt-get install libapache2-mod-wsgi</span></p>
<p>Now for the configuration. It took me a few tries to get this right.<br />
For now I just put my django site on port 8080 so I can play around without it being public to anyone else.</p>
<p>In the /var/django/mysite/apache directory I created a file called django.wsgi and put this in it:</p>
<p><span style="color: #888888;">import os, sys<br />
apache_configuration= os.path.dirname(__file__)<br />
project = os.path.dirname(apache_configuration)<br />
sys.path.append(&#8217;/var/django&#8217;)<br />
os.environ['DJANGO_SETTINGS_MODULE'] = &#8216;mysite.settings&#8217;<br />
import django.core.handlers.wsgi<br />
application = django.core.handlers.wsgi.WSGIHandler()</span></p>
<p>Make sure that the sys.path.append line contains the directory above the project directory. This one took me awhile to figure out.<br />
I was getting this error until I got it right.<br />
<span style="color: #ff0000;"><br />
[Sat May 30 15:33:24 2009] [error] [client 127.0.0.1]     raise ImportError, &#8220;Could not import settings &#8216;%s&#8217; (Is it on sys.path? Does it have syntax errors?): %s&#8221; % (self.SETTINGS_MODULE, e)<br />
[Sat May 30 15:33:24 2009] [error] [client 127.0.0.1] ImportError: Could not import settings &#8216;mysite.settings&#8217; (Is it on sys.path? Does it have syntax errors?): No module named mysite.settings</span></p>
<p>Next I added a new virtual host in my sites-enabled folder like this:</p>
<p><span style="color: #808080;">&lt;VirtualHost *:808http://localhost:8080/0&gt;<br />
ServerAdmin root@mysite.com<br />
ServerName mysite.com<br />
ServerAlias mysite.com<br />
&lt;Directory /var/django/mysite/apache&gt;<br />
Allow from all<br />
&lt;/Directory&gt;</span></p>
<p><span style="color: #888888;">WSGIDaemonProcess www-data<br />
WSGIProcessGroup www-data<br />
WSGIScriptAlias / /var/django/mysite/apache/django.wsgi<br />
&lt;/VirtualHost&gt;</span></p>
<p>After restarting apache :<br />
<span style="color: #808080;">sudo /etc/init.d/apache2 restart</span></p>
<p>I got an &#8220;It Worked&#8221; page when I point my browser to http://localhost:8080/</p>
<p>Of course this doesn&#8217;t allow you to use a database in your applications yet but it&#8217;s a start.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F05%2Fdjango-quick-install-with-wsgi.html&amp;linkname=Django%20Quick%20Install%20With%20WSGI"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/05/django-quick-install-with-wsgi.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

