<?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>Perplexed Labs &#187; string</title>
	<atom:link href="http://blog.perplexedlabs.com/tag/string/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.perplexedlabs.com</link>
	<description>web development war stories from the frontlines to the backend</description>
	<lastBuildDate>Mon, 16 May 2011 14:19:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Django URL Parameter Passing and Python Strings</title>
		<link>http://blog.perplexedlabs.com/2009/04/22/django-url-parameter-passing-and-python-strings/</link>
		<comments>http://blog.perplexedlabs.com/2009/04/22/django-url-parameter-passing-and-python-strings/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 16:18:01 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.perplexedlabs.com/?p=224</guid>
		<description><![CDATA[This post is simply stating the obvious. Sometimes even obvious things, in the wee hours of the morning, aren't so. When you specify parameters in your URLconf like: urlpatterns = patterns('', url(r'^mark/(?P&#60;id&#62;\d+)/(?P&#60;complete&#62;\d+)/$', views.mark, name='mark'), ) Keep in mind that each captured argument is a Python string. Even if the regex only captures integers - 'complete' [...]


Related posts:<ol><li><a href='http://blog.perplexedlabs.com/2009/08/13/adventures-in-django-and-python-part-iii/' rel='bookmark' title='Permanent Link: Adventures in Django and Python &#8211; Part III'>Adventures in Django and Python &#8211; Part III</a></li>
<li><a href='http://blog.perplexedlabs.com/2010/09/09/python-libwkhtmltox-module-wrapping-a-c-library-using-cython/' rel='bookmark' title='Permanent Link: Python libwkhtmltox module &#8211; wrapping a C library using Cython &#8211; convert HTML to PDF'>Python libwkhtmltox module &#8211; wrapping a C library using Cython &#8211; convert HTML to PDF</a></li>
<li><a href='http://blog.perplexedlabs.com/2009/03/20/django-and-python-first-impressions-part-ii/' rel='bookmark' title='Permanent Link: Django and Python First Impressions &#8211; Part II'>Django and Python First Impressions &#8211; Part II</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This post is simply stating the obvious.  Sometimes even obvious things, in the wee hours of the morning, aren't so.</p>
<p>When you specify parameters in your URLconf like:</p>
<pre class="brush: python; title: ;">
urlpatterns = patterns('',
    url(r'^mark/(?P&lt;id&gt;\d+)/(?P&lt;complete&gt;\d+)/$', views.mark, name='mark'),
)
</pre>
<p>Keep in mind that each captured argument is a Python string.  Even if the regex only captures integers - 'complete' is still passed as a Python string to your 'mark' view.</p>
<p>So if you intended to pass a 0 for false and 1 for true you must make sure to convert to an integer because only a string of length 0 is False.  ('0' == True)</p>
<pre class="brush: python; title: ;">
def mark(request, id, complete):
    todo = get_object_or_404(pk=id)
    todo.complete = int(complete)
    todo.save()
    return HttpResponse()
</pre>


<p>Related posts:<ol><li><a href='http://blog.perplexedlabs.com/2009/08/13/adventures-in-django-and-python-part-iii/' rel='bookmark' title='Permanent Link: Adventures in Django and Python &#8211; Part III'>Adventures in Django and Python &#8211; Part III</a></li>
<li><a href='http://blog.perplexedlabs.com/2010/09/09/python-libwkhtmltox-module-wrapping-a-c-library-using-cython/' rel='bookmark' title='Permanent Link: Python libwkhtmltox module &#8211; wrapping a C library using Cython &#8211; convert HTML to PDF'>Python libwkhtmltox module &#8211; wrapping a C library using Cython &#8211; convert HTML to PDF</a></li>
<li><a href='http://blog.perplexedlabs.com/2009/03/20/django-and-python-first-impressions-part-ii/' rel='bookmark' title='Permanent Link: Django and Python First Impressions &#8211; Part II'>Django and Python First Impressions &#8211; Part II</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.perplexedlabs.com/2009/04/22/django-url-parameter-passing-and-python-strings/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

