<?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>Pressing the Red Button &#187; Django</title>
	<atom:link href="http://www.pressthered.com/tag/django/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pressthered.com</link>
	<description>Adventures in Software Development</description>
	<lastBuildDate>Sun, 05 Sep 2010 16:55:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Delete an Index in an AppEngine Datastore</title>
		<link>http://www.pressthered.com/how_to_delete_an_index_in_an_appengine_datastore/</link>
		<comments>http://www.pressthered.com/how_to_delete_an_index_in_an_appengine_datastore/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 03:23:49 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Google AppEngine]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=804</guid>
		<description><![CDATA[If using Python, you can delete an index by first removing the entry in your index.yaml file, and then updating your site. Then you must issue this command:
appcfg.py vacuum_indexes myapp/
With Django (what I am using), you use this command:
manage.py vacuum_indexes
What is nice about the process is that, for each index that has been removed from [...]]]></description>
			<content:encoded><![CDATA[<p>If using Python, you can delete an index by first removing the entry in your index.yaml file, and then updating your site. Then you must issue this command:<br />
<strong>appcfg.py vacuum_indexes myapp/</strong></p>
<p>With Django (what I am using), you use this command:<br />
<strong>manage.py vacuum_indexes</strong></p>
<p>What is nice about the process is that, for each index that has been removed from your index.yaml, it will confirm whether you want to delete it or not. So you get a second chance to make sure you are right. If you delete the wrong index, it&#8217;s going to take some <a href="http://code.google.com/appengine/articles/index_building.html">time for it to rebuild</a>, and portions of your site could be down.</p>
<p><strong>Why do I need this:</strong><br />
I don&#8217;t think you would see a noticeable speed improvement to your data inserts, updates, or deletes by having a few less unused indexes, but it couldn&#8217;t hurt. Also you are limited to 100 indexes (as of April 2010) so this how you free them up.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/how_to_delete_an_index_in_an_appengine_datastore/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google AppEngine: appcfg.py update check failed</title>
		<link>http://www.pressthered.com/google_appengine_appcfgpy_update_check_failed/</link>
		<comments>http://www.pressthered.com/google_appengine_appcfgpy_update_check_failed/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 04:55:18 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Google AppEngine]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=800</guid>
		<description><![CDATA[I started getting this error in Windows when running &#8216;manage runserver&#8217; in django on Google AppEngine:
appcfg.py update check failed: EOF occurred in violation of protocol
This error is related to not having the SSL module for python installed. The easy fix is to install it by running &#8220;easy_install ssl&#8221; from the command prompt. However, using Python [...]]]></description>
			<content:encoded><![CDATA[<p>I started getting this error in Windows when running &#8216;manage runserver&#8217; in django on Google AppEngine:</p>
<p><strong>appcfg.py update check failed: EOF occurred in violation of protocol</strong></p>
<p>This error is related to not having the SSL module for python installed. The easy fix is to install it by running &#8220;easy_install ssl&#8221; from the command prompt. However, using Python 2.5, I received errors and it did not work. </p>
<p>The longer, more involved fix is to compile the SSL module for python. This was a hassle but after about an hour I finally got it working.</p>
<p>Here is the tutorial I used to install the ssl module:<br />
<a href="http://beautifulisbetterthanugly.com/posts/2009/aug/19/compile-ssl-115-python-25-or-lower/">http://beautifulisbetterthanugly.com/posts/2009/aug/19/compile-ssl-115-python-25-or-lower/</a></p>
<p>I also had to follow the troubleshooting section on this link:<br />
<a href="http://wiki.cython.org/InstallingOnWindows">http://wiki.cython.org/InstallingOnWindows</a><br />
because I did not have the python library file (libpython25.a).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/google_appengine_appcfgpy_update_check_failed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing Email Locally with AppEngine Patch on Windows</title>
		<link>http://www.pressthered.com/testing_email_locally_with_appengine_patch_on_windows/</link>
		<comments>http://www.pressthered.com/testing_email_locally_with_appengine_patch_on_windows/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 05:21:52 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Google AppEngine]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=785</guid>
		<description><![CDATA[If you need to get email working on your windows dev machine for Google AppEngine, here is one method:

Download Fake Sendmail for Windows. Unzip the files and copy them into a new folder.
Add this new folder to your windows PATH, by right clicking on My Computer -> Properties. Click Advanced Tab -> Environmental Variables. Edit [...]]]></description>
			<content:encoded><![CDATA[<p>If you need to get email working on your windows dev machine for Google AppEngine, here is one method:</p>
<ol>
<li>Download <a href="http://glob.com.au/sendmail/">Fake Sendmail for Windows.</a> Unzip the files and copy them into a new folder.</li>
<li>Add this new folder to your windows PATH, by right clicking on My Computer -> Properties. Click Advanced Tab -> Environmental Variables. Edit the PATH variable under System variables. Append your path to the end of the string. Do not replace the existing paths, just add it to the end preceded by a semi colon. Ex: &#8220;;c:\apps\fakesendmail&#8221;</li>
<li>In your fakesendmail folder, you must configure the &#8220;sendmail.ini&#8221; file. You have two choices:
<ul>
<li>Use your own custom smtp server settings (if you have one), by setting &#8220;smtp_server&#8221;, &#8220;auth_username&#8221;, &#8220;auth_password&#8221;, and &#8220;default_domain&#8221;</li>
<li>Use Windows default smtp service by setting &#8220;smtp_server&#8221; to &#8220;C:\Inetpub\mailroot\Pickup&#8221; and &#8220;default_domain&#8221; to &#8220;localhost&#8221;. This second choice will not send your emails but most likely will store your emails in the &#8220;C:\Inetpub\mailroot\Queue&#8221;.</li>
</ul>
</li>
<li>Open a new command console (must reopen the console to pick up the new path variable). Run the appengine patch from your apps root folder with the following argument:<br />
<strong> &#8220;manage runserver &#8211;enable_sendmail&#8221;</strong></li>
</ol>
<p><strong>Some Additional Info:</strong><br />
This will resolve the error message &#8220;SMTP AUTH extension not supported by server&#8221;.</p>
<p>These steps were derived from this <a href="http://groups.google.com/group/app-engine-patch/msg/9cca92df4b993d6c?pli=1">google discussion</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/testing_email_locally_with_appengine_patch_on_windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shopper Talk Goes Live</title>
		<link>http://www.pressthered.com/shopper_talk_goes_live/</link>
		<comments>http://www.pressthered.com/shopper_talk_goes_live/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 04:15:06 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Shopper Talk]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[google app engine]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=740</guid>
		<description><![CDATA[My latest project for Twitter. Try it out! 
http://shoppertalk.appspot.com
It&#8217;s unbreakable. Ok, that&#8217;s not true, but I do need some testers. 
It&#8217;s a Django app running on Google App Engine. It utilizes the Twitter api and their OAuth implementation (so you can log in with your Twitter account).
Currently only the Amazon product catalog is available for [...]]]></description>
			<content:encoded><![CDATA[<p>My latest project for Twitter. Try it out! </p>
<p><a href="http://shoppertalk.appspot.com">http://shoppertalk.appspot.com</a></p>
<p>It&#8217;s unbreakable. Ok, that&#8217;s not true, but I do need some testers. </p>
<p>It&#8217;s a <a href="http://djangoproject.com">Django</a> app running on <a href="http://code.google.com/appengine/">Google App Engine</a>. It utilizes the Twitter api and their OAuth implementation (so you can log in with your Twitter account).</p>
<p>Currently only the Amazon product catalog is available for browsing, but more will be added. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/shopper_talk_goes_live/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UrlEncode in Python</title>
		<link>http://www.pressthered.com/urlencode_in_python/</link>
		<comments>http://www.pressthered.com/urlencode_in_python/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 05:36:55 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=719</guid>
		<description><![CDATA[To urlencode a querystring or form data in python you can use the urllib module:

use urllib
# you have to pass in a dictionary
print urllib.urlencode({'id':'100', 'name':'john smith'})

# then you get 'id=100&#038;name=john+smith'

Urlencoding Unicode and UTF8 Values

#this works fine
print urllib.urlencode({name:'José'})

#you have to be careful with unicode strings
# this will throw an error:
print urllib.urlencode({name:u'José'})
# UnicodeDecodeError: 'ascii' codec can't decode [...]]]></description>
			<content:encoded><![CDATA[<p><strong>To urlencode a querystring or form data in python you can use the urllib module:</strong></p>
<pre name="code" class="python">
use urllib
# you have to pass in a dictionary
print urllib.urlencode({'id':'100', 'name':'john smith'})

# then you get 'id=100&#038;name=john+smith'
</pre>
<p><strong>Urlencoding Unicode and UTF8 Values</strong></p>
<pre name="code" class="python">
#this works fine
print urllib.urlencode({name:'José'})

#you have to be careful with unicode strings
# this will throw an error:
print urllib.urlencode({name:u'José'})
# UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in
# position 11: ordinal not in range

#since the default ascii conversion can't handle the 'é',
# you have to be explicit in what charset you are using
print urllib.urlencode({'name':u'José'.encode('utf8')})
</pre>
<p><strong>Additional Info:</strong><br />
<a href="http://docs.python.org/library/urllib.html#urllib.urlencode">Python Doc for urllib module</a><br />
<a href="http://www.joelonsoftware.com/articles/Unicode.html">Unicode Primer</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/urlencode_in_python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using a favicon in Django</title>
		<link>http://www.pressthered.com/using_a_favicon_in_django/</link>
		<comments>http://www.pressthered.com/using_a_favicon_in_django/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 06:23:20 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[Django]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=658</guid>
		<description><![CDATA[The default location for a favicon.ico file is the root folder of website. However when using Django with an apache virtualhost, you need to map the location of your favicon. 
Here are a few ways to get you favicon working:
1) The quick way is to modify the html in your base template to include the [...]]]></description>
			<content:encoded><![CDATA[<p>The default location for a favicon.ico file is the root folder of website. However when using Django with an apache virtualhost, you need to map the location of your favicon. </p>
<p>Here are a few ways to get you favicon working:</p>
<p>1) The quick way is to modify the html in your base template to include the shortcut link. This assumes that you have already <a href="http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#id1">mapped a media folder</a> called &#8220;media&#8221;:</p>
<pre name="code" class="html">
&lt;link REL="SHORTCUT ICON" HREF="/media/favicon.ico">
</pre>
<p>2) Probably the more proper way is to modify your httpd.conf file:<br />
<code><br />
&lt;LocationMatch "^/favicon.ico"><br />
        SetHandler default<br />
&lt;/LocationMatch><br />
alias /favicon.ico /directory-to-icon/static/favicon.ico</p>
<p></code></p>
<p><strong>How Can I Make a Favicon</strong><br />
Here is an online tool to quickly <a href="http://tools.dynamicdrive.com/favicon/">create a favicon</a>, by uploading an image.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/using_a_favicon_in_django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamically Importing and Instantiating Modules in Python</title>
		<link>http://www.pressthered.com/dynamically_importing_and_instantiating_modules_in_python/</link>
		<comments>http://www.pressthered.com/dynamically_importing_and_instantiating_modules_in_python/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 05:43:20 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=634</guid>
		<description><![CDATA[Also called reflection, here is one method to import modules and instantiate objects using strings:


moduleName = 'myApp.models'
className = 'Blog'

#import the module by saying 'from myApp.models import Blog'
module = __import__(moduleName, {}, {}, className)

#now you can instantiate the class
obj = getattr(module, className )()

#set a property of the object using a string
setattr('Title','my first entry')

#call an existing method you [...]]]></description>
			<content:encoded><![CDATA[<p>Also called reflection, here is one method to import modules and instantiate objects using strings:</p>
<pre name="code" class="python">

moduleName = 'myApp.models'
className = 'Blog'

#import the module by saying 'from myApp.models import Blog'
module = __import__(moduleName, {}, {}, className)

#now you can instantiate the class
obj = getattr(module, className )()

#set a property of the object using a string
setattr('Title','my first entry')

#call an existing method you already know
obj.save()
</pre>
<p>I was using Python 2.5, so it is probably safe to say the code above is at least Python 2.5+ compatible.</p>
<p>Some additional references:<br />
<a href="http://diveintopython.org/power_of_introspection/getattr.html">Dive Into Python &#8211; The Power of Introspection</a><br />
<a href="http://www.python.org/doc/2.5.1/lib/built-in-funcs.html">Python Manual &#8211; Built In Functions</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/dynamically_importing_and_instantiating_modules_in_python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resolving DJANGO Error: &#8220;ValueError: invalid literal for int() with base 10: &#8216;None&#8217;&#8221;</title>
		<link>http://www.pressthered.com/resolving_django_error_valueerror_invalid_literal_for_int_with_base_10_none/</link>
		<comments>http://www.pressthered.com/resolving_django_error_valueerror_invalid_literal_for_int_with_base_10_none/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 05:39:55 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=614</guid>
		<description><![CDATA[If you receive this error via email while viewing one of your admin pages, here are some steps to help resolve it. First note the problem URL. It should be in the detailed error email. Try the url in your browser and verify you receive the same error. Now you have to find the page [...]]]></description>
			<content:encoded><![CDATA[<p>If you receive this error via email while viewing one of your admin pages, here are some steps to help resolve it. First note the problem URL. It should be in the detailed error email. Try the url in your browser and verify you receive the same error. Now you have to find the page that is linking to this invalid URL. </p>
<p>In my case, it was an image tag that I included in the admin <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display">list display</a>. In my custom field code, I did not handle the &#8220;None&#8221; case. So instead of displaying a broken link it was trying to load the None image in my admin directory. Generating the URL that was causing the issue:<br />
/admin/myApp/myModel/None/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/resolving_django_error_valueerror_invalid_literal_for_int_with_base_10_none/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Distinct Rows Using Django Database Layer</title>
		<link>http://www.pressthered.com/getting_distinct_rows_using_django_database_layer/</link>
		<comments>http://www.pressthered.com/getting_distinct_rows_using_django_database_layer/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 05:20:45 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=572</guid>
		<description><![CDATA[To get the equivalent of the SQL select distinct statement in Django, you can use a combination of the values() and distinct() method of the QuerySet api.
For example, you have a musicians table and you want to get list of instruments that they play (with no duplicates):


Musicians.objects.values('instrument').distinct()

The values(&#8217;instrument&#8217;) method will generate a select statment of [...]]]></description>
			<content:encoded><![CDATA[<p>To get the equivalent of the SQL select distinct statement in Django, you can use a combination of the values() and distinct() method of the <a href="http://docs.djangoproject.com/en/dev/ref/models/querysets">QuerySet api</a>.</p>
<p>For example, you have a musicians table and you want to get list of instruments that they play (with no duplicates):</p>
<pre name="code" class="python">

Musicians.objects.values('instrument').distinct()
</pre>
<p>The values(&#8217;instrument&#8217;) method will generate a select statment of just the column instrument, while the distinct() method will apply the SELECT DISTINCT to the sql statement. The equivalent sql generated is: &#8220;select distinct instrument from musician&#8221;</p>
<p>One item to note (<a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct">mentioned in the documentation</a>), is when using the orderby() method to sort your data, the fields specified in the order by will also be included in the select statement. So you just have to be aware of it, especially if your results are not coming out as expected.</p>
<p>For example:</p>
<pre name="code" class="python">
# Possible gotcha
Musicians.objects.values('instrument').distinct().orderby('instrument_model_num')
</pre>
<p>The equivalent sql that is generated is &#8220;select distinct instrument, instrument_model_num from musician order by instrument_model_num&#8221;. This will not get you a list of just the instruments that the musicians play.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/getting_distinct_rows_using_django_database_layer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Get a Client IP Address in DJANGO</title>
		<link>http://www.pressthered.com/how_to_get_a_client_ip_address_in_django/</link>
		<comments>http://www.pressthered.com/how_to_get_a_client_ip_address_in_django/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 06:29:37 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=563</guid>
		<description><![CDATA[Here is a small snippet to get the client&#8217;s ip address in your python code in DJANGO. You might have tried the &#8216;REMOTE_ADDR&#8217; key in the request object but it always returns 127.0.0.1. To fix this, you can use the &#8216;HTTP_X_FORWARDED_FOR&#8217; variable like so:


from django.http import HttpRequest

def mypage(request):
	client_address = request.META['HTTP_X_FORWARDED_FOR']
	....

The HTTP_X_FORWARDED_FOR variable stores the client&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a small snippet to get the client&#8217;s ip address in your python code in DJANGO. You might have tried the &#8216;REMOTE_ADDR&#8217; key in the request object but it always returns 127.0.0.1. To fix this, you can use the &#8216;HTTP_X_FORWARDED_FOR&#8217; variable like so:</p>
<pre name="code" class="python">

from django.http import HttpRequest

def mypage(request):
	client_address = request.META['HTTP_X_FORWARDED_FOR']
	....
</pre>
<p>The <a href="http://en.wikipedia.org/wiki/X-Forwarded-For">HTTP_X_FORWARDED_FOR</a> variable stores the client&#8217;s ip when the user is going through a proxy or load balancer. </p>
<p>I ran into this issue when running my Django app on apache. All lookups of the &#8216;REMOTE_ADDR&#8217; return localhost (127.0.0.1). This is probably a side affect of how the python module runs in apache.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/how_to_get_a_client_ip_address_in_django/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
