<?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>/kb &#187; web</title>
	<atom:link href="http://grx.no/kb/tag/web/feed/" rel="self" type="application/rss+xml" />
	<link>http://grx.no/kb</link>
	<description>personal knowledgebase</description>
	<lastBuildDate>Wed, 15 Jun 2011 07:07:47 +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>Chapter 7 in &#8220;Python Web Development with Django&#8221; &#8211; some notes</title>
		<link>http://grx.no/kb/2009/03/08/chapter-7-in-python-web-development-with-django-some-notes/</link>
		<comments>http://grx.no/kb/2009/03/08/chapter-7-in-python-web-development-with-django-some-notes/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 18:08:07 +0000</pubDate>
		<dc:creator>Morten Wergeland Hansen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://grx.no/kb/?p=103</guid>
		<description><![CDATA[I am currently in the process of learning Django and have just finished chapter 7 in Python Web Development with Django. Here are some notes on how I got it working (except for the index page which still isn&#8217;t completely as expected) on an ubuntu hardy installation. The photo gallery example assumes an apache2 + [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently in the process of learning Django and have just finished chapter 7 in <a href="http://withdjango.com">Python Web Development with Django</a>. Here are some notes on how I got it working (except for the index page which still isn&#8217;t completely as expected) on an ubuntu hardy installation.</p>
<p>The photo gallery example assumes an <em>apache2</em> + <em>mod_python</em> setup. I didn&#8217;t really find it straightforward to get this running from the description in the appendix, so here is how I got it to work (after installation of <em>apache2</em> and <em>mod_python</em>, of course):</p>
<p>In <em>/etc/apache2/sites-available/default</em>, change lines:</p>
<pre>        &lt;Directory /var/www/&gt;
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        &lt;/Directory&gt;</pre>
<p>To:</p>
<pre>        &lt;Directory /var/www/&gt;
                Options Indexes FollowSymLinks MultiViews
                AllowOverride AuthConfig
                Order allow,deny
                allow from all

                AddHandler mod_python .py
                PythonHandler mod_python.publisher
                PythonDebug On
        &lt;/Directory&gt;</pre>
<p>Then I did the changes in <em>/etc/apache2/httpd.conf</em>, but slightly different from the book by adding a <code>PythonOption django.root</code> (didn&#8217;t work for me with the setup in the book):</p>
<pre>&lt;Location "/gallery/"&gt;
      SetHandler python-program
      PythonHandler django.core.handlers.modpython
      SetEnv DJANGO_SETTINGS_MODULE gallery.settings
      PythonOption django.root /gallery
      PythonDebug On
      PythonPath "['/path/to/django/root', '/home/user/django-stuff'] + sys.path"
&lt;/Location&gt;</pre>
<p>With an additional entry for media files:</p>
<pre>&lt;Location "/gallery/media"&gt;
      SetHandler none
&lt;/Location&gt;</pre>
<p>Now, I created a directory <em>/var/www/gallery</em> and a <em>/var/www/gallery/media</em> like explained in &#8220;Preparing for File Uploads&#8221; and edited <em>settings.py</em>:</p>
<p><code>MEDIA_ROOT = '/var/www/gallery/media/'</code><br />
<code>MEDIA_URL = 'http://localhost/gallery/media/'</code><br />
<code>ADMIN_MEDIA_PREFIX = 'http://localhost/gallery/media/admin/'</code></p>
<p>Where admin is a symbolic link (<em>/var/www/gallery/media/admin</em>) to the admin media directory in the Django installation. The two last entries where not mentioned in the book, but they made it work&#8230;</p>
<p>With the settings described above and the <code>PythonOption django.root</code> in <em>httpd.conf</em>, I didn&#8217;t need the section about DRY URLs. And it worked &#8211; as opposed to the stuff in the book.</p>
<p>With all the configuration stuff in place I typed the code outlined in the chapter and to begin with I couldn&#8217;t see any photos, except for the <code>thumb_url</code> in <em>items_list.html</em> (typo: <em>items_listing.html</em> in the last paragraph page 175). I managed to get it working by changing some lines in <em>items_detail.html</em> and <em>photos_detail.html</em> though:</p>
<pre>22                 &lt;img src="{{ photo.image.thumb_url }}" /&gt;</pre>
<p>instead of</p>
<pre>22                 &lt;img src="{{ photo.get_image_thumb_url }}" /&gt;</pre>
<p>and</p>
<pre>8 &lt;img src="{{ object.image.url }}" /&gt;</pre>
<p>instead of:</p>
<pre>8 &lt;img src="{{ object.get_image_url }}" /&gt;</pre>
<p>The alternatives that worked seems more intuitive to me.</p>
<p>I also imported <code>list_detail</code> from <code>django.views.generic</code> in <em>urls.py</em>, but am not sure if this was needed. The photo gallery seems to work fine except for the thumbnails in <em>index.html</em>. I&#8217;ve noticed that the code in <em>urls.py</em> for that template is different from the others, using <code>simple.direct_to_template</code>, but I haven&#8217;t managed getting that part to work.</p>
<p>Thanks to this thread for getting mod_python up and running: <a href="http://ubuntuforums.org/showthread.php?t=91101">Python and Apache2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://grx.no/kb/2009/03/08/chapter-7-in-python-web-development-with-django-some-notes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

