<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Using Subdomains in Django</title>
	<atom:link href="http://thingsilearned.com/2009/01/05/using-subdomains-in-django/feed/" rel="self" type="application/rss+xml" />
	<link>http://thingsilearned.com/2009/01/05/using-subdomains-in-django/</link>
	<description>something new every day ... or so  By Dave Fowler</description>
	<lastBuildDate>Sun, 05 Feb 2012 13:43:41 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Joe Tsai</title>
		<link>http://thingsilearned.com/2009/01/05/using-subdomains-in-django/#comment-999</link>
		<dc:creator><![CDATA[Joe Tsai]]></dc:creator>
		<pubDate>Fri, 02 Dec 2011 01:26:38 +0000</pubDate>
		<guid isPermaLink="false">http://thingsilearned.wordpress.com/?p=195#comment-999</guid>
		<description><![CDATA[Kind of a late post, but if anyone cares... Rather than parse out the subdomain and store it in the request, I just wanted to be able to handle sub-domains via Django&#039;s built in URL dispatcher.

The following modification remains backwards compatible with the exist URL patterns. The modification changes the path_info value used by the dispatcher. Patterns used to identify paths originating from a subdomain simply need to search for the regex pattern &#039;^/subname/&#039;.

&lt;code&gt;
&#039;&#039;&#039;
Example:
&#039;domain.com&#039;           -&gt; &#039;&#039;
&#039;domain.com/doc&#039;       -&gt; &#039;doc&#039;
&#039;domain.com/doc/&#039;      -&gt; &#039;doc/&#039;
&#039;sub.domain.com&#039;       -&gt; &#039;/sub/&#039;
&#039;sub.domain.com/doc&#039;   -&gt; &#039;/sub/doc&#039;
&#039;sub.domain.com/doc/&#039;  -&gt; &#039;/sub/doc/&#039;
&#039;domain.com/foo&#039;       -&gt; &#039;foo&#039;
&#039;foo.domain.com&#039;       -&gt; &#039;/foo/&#039;
&#039;sub1.sub2.domain.com&#039; -&gt; &#039;/sub1_sub2/&#039;
&#039;&#039;&#039;

class SubdomainMiddleware:
    def process_request(self, request):
        http_host = request.META.get(&#039;HTTP_HOST&#039;, &#039;&#039;)
        sub_chunks = http_host.replace(&#039;www.&#039;, &#039;&#039;).lower().split(&#039;.&#039;)[:-2]
        if len(sub_chunks) != 0:
            subdomain = &quot;_&quot;.join(sub_chunks)
            request.path_info = &quot;//&quot; + subdomain + request.path_info
&lt;/code&gt;

Tested with Django 1.3.1 and Python 2.7]]></description>
		<content:encoded><![CDATA[<p>Kind of a late post, but if anyone cares&#8230; Rather than parse out the subdomain and store it in the request, I just wanted to be able to handle sub-domains via Django&#8217;s built in URL dispatcher.</p>
<p>The following modification remains backwards compatible with the exist URL patterns. The modification changes the path_info value used by the dispatcher. Patterns used to identify paths originating from a subdomain simply need to search for the regex pattern &#8216;^/subname/&#8217;.</p>
<p><code><br />
'''<br />
Example:<br />
'domain.com'           -&gt; ''<br />
'domain.com/doc'       -&gt; 'doc'<br />
'domain.com/doc/'      -&gt; 'doc/'<br />
'sub.domain.com'       -&gt; '/sub/'<br />
'sub.domain.com/doc'   -&gt; '/sub/doc'<br />
'sub.domain.com/doc/'  -&gt; '/sub/doc/'<br />
'domain.com/foo'       -&gt; 'foo'<br />
'foo.domain.com'       -&gt; '/foo/'<br />
'sub1.sub2.domain.com' -&gt; '/sub1_sub2/'<br />
'''</p>
<p>class SubdomainMiddleware:<br />
    def process_request(self, request):<br />
        http_host = request.META.get('HTTP_HOST', '')<br />
        sub_chunks = http_host.replace('www.', '').lower().split('.')[:-2]<br />
        if len(sub_chunks) != 0:<br />
            subdomain = "_".join(sub_chunks)<br />
            request.path_info = "//" + subdomain + request.path_info<br />
</code></p>
<p>Tested with Django 1.3.1 and Python 2.7</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nav</title>
		<link>http://thingsilearned.com/2009/01/05/using-subdomains-in-django/#comment-889</link>
		<dc:creator><![CDATA[nav]]></dc:creator>
		<pubDate>Sat, 19 Feb 2011 03:00:11 +0000</pubDate>
		<guid isPermaLink="false">http://thingsilearned.wordpress.com/?p=195#comment-889</guid>
		<description><![CDATA[Thanks Dave for your reply.

It all works now. 

Never would have guessed that the port number was confusing /etc/hosts.

Cheers,
nav]]></description>
		<content:encoded><![CDATA[<p>Thanks Dave for your reply.</p>
<p>It all works now. </p>
<p>Never would have guessed that the port number was confusing /etc/hosts.</p>
<p>Cheers,<br />
nav</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: godavemon</title>
		<link>http://thingsilearned.com/2009/01/05/using-subdomains-in-django/#comment-888</link>
		<dc:creator><![CDATA[godavemon]]></dc:creator>
		<pubDate>Thu, 17 Feb 2011 23:08:03 +0000</pubDate>
		<guid isPermaLink="false">http://thingsilearned.wordpress.com/?p=195#comment-888</guid>
		<description><![CDATA[Thanks!  I think you actually want this in your localhost

127.0.0.1  subdomain.locahost

Also I find its more useful to use more fun names other than localhost like

127.0.0.1  subdomain.mysite-dev.com

But yeah, the port number :8000 will just confuse the hosts file.]]></description>
		<content:encoded><![CDATA[<p>Thanks!  I think you actually want this in your localhost</p>
<p>127.0.0.1  subdomain.locahost</p>
<p>Also I find its more useful to use more fun names other than localhost like</p>
<p>127.0.0.1  subdomain.mysite-dev.com</p>
<p>But yeah, the port number :8000 will just confuse the hosts file.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nav</title>
		<link>http://thingsilearned.com/2009/01/05/using-subdomains-in-django/#comment-887</link>
		<dc:creator><![CDATA[nav]]></dc:creator>
		<pubDate>Thu, 17 Feb 2011 17:05:10 +0000</pubDate>
		<guid isPermaLink="false">http://thingsilearned.wordpress.com/?p=195#comment-887</guid>
		<description><![CDATA[Dear Dave,

Thank you for posting up this solution.

I am trying out what you suggested but I am not able to get the URL to the middleware. The URL I am using is of the form subdomain.localhost:8000. I have also modified my /etc/hosts file as:

127.0.0.1:8000 subdomain.localhost:8000

must I disconnect myself from the internet for this to work? Or must I  run the development server 127.0.0.1 without the port number. Kindly please shed some light.

Cheers.
nav]]></description>
		<content:encoded><![CDATA[<p>Dear Dave,</p>
<p>Thank you for posting up this solution.</p>
<p>I am trying out what you suggested but I am not able to get the URL to the middleware. The URL I am using is of the form subdomain.localhost:8000. I have also modified my /etc/hosts file as:</p>
<p>127.0.0.1:8000 subdomain.localhost:8000</p>
<p>must I disconnect myself from the internet for this to work? Or must I  run the development server 127.0.0.1 without the port number. Kindly please shed some light.</p>
<p>Cheers.<br />
nav</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe Casper</title>
		<link>http://thingsilearned.com/2009/01/05/using-subdomains-in-django/#comment-883</link>
		<dc:creator><![CDATA[Joe Casper]]></dc:creator>
		<pubDate>Fri, 28 Jan 2011 16:54:34 +0000</pubDate>
		<guid isPermaLink="false">http://thingsilearned.wordpress.com/?p=195#comment-883</guid>
		<description><![CDATA[Just found this little gem of a script. Incredibly useful Worked perfectly with the tweaks suggested in the comments.]]></description>
		<content:encoded><![CDATA[<p>Just found this little gem of a script. Incredibly useful Worked perfectly with the tweaks suggested in the comments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The PickledObjectField for Object Storage in Django &#171; ThingsILearned</title>
		<link>http://thingsilearned.com/2009/01/05/using-subdomains-in-django/#comment-874</link>
		<dc:creator><![CDATA[The PickledObjectField for Object Storage in Django &#171; ThingsILearned]]></dc:creator>
		<pubDate>Thu, 06 Jan 2011 01:47:58 +0000</pubDate>
		<guid isPermaLink="false">http://thingsilearned.wordpress.com/?p=195#comment-874</guid>
		<description><![CDATA[[...] incredibly rare that a django snippet becomes such a major tool.  With the exception of my subdomain middleware, I can&#8217;t think of another snippet that I use more regularly which leads me to think that it [...]]]></description>
		<content:encoded><![CDATA[<p>[...] incredibly rare that a django snippet becomes such a major tool.  With the exception of my subdomain middleware, I can&#8217;t think of another snippet that I use more regularly which leads me to think that it [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sphere</title>
		<link>http://thingsilearned.com/2009/01/05/using-subdomains-in-django/#comment-872</link>
		<dc:creator><![CDATA[sphere]]></dc:creator>
		<pubDate>Sat, 25 Dec 2010 15:47:18 +0000</pubDate>
		<guid isPermaLink="false">http://thingsilearned.wordpress.com/?p=195#comment-872</guid>
		<description><![CDATA[dodolboks, how did you solved this ?]]></description>
		<content:encoded><![CDATA[<p>dodolboks, how did you solved this ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Домен второго уровня и проект</title>
		<link>http://thingsilearned.com/2009/01/05/using-subdomains-in-django/#comment-866</link>
		<dc:creator><![CDATA[Домен второго уровня и проект]]></dc:creator>
		<pubDate>Mon, 13 Dec 2010 12:48:35 +0000</pubDate>
		<guid isPermaLink="false">http://thingsilearned.wordpress.com/?p=195#comment-866</guid>
		<description><![CDATA[[...] Пример: http://thingsilearned.com/2009/01/05/using-subdomains-in-django/ [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Пример: <a href="http://thingsilearned.com/2009/01/05/using-subdomains-in-django/" rel="nofollow">http://thingsilearned.com/2009/01/05/using-subdomains-in-django/</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jholster</title>
		<link>http://thingsilearned.com/2009/01/05/using-subdomains-in-django/#comment-840</link>
		<dc:creator><![CDATA[jholster]]></dc:creator>
		<pubDate>Sun, 21 Nov 2010 12:27:27 +0000</pubDate>
		<guid isPermaLink="false">http://thingsilearned.wordpress.com/?p=195#comment-840</guid>
		<description><![CDATA[Use subdomains easily on localhost: (no /etc/hosts modification required)

http://tbaggery.com/2010/03/04/smack-a-ho-st.html]]></description>
		<content:encoded><![CDATA[<p>Use subdomains easily on localhost: (no /etc/hosts modification required)</p>
<p><a href="http://tbaggery.com/2010/03/04/smack-a-ho-st.html" rel="nofollow">http://tbaggery.com/2010/03/04/smack-a-ho-st.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Olav</title>
		<link>http://thingsilearned.com/2009/01/05/using-subdomains-in-django/#comment-820</link>
		<dc:creator><![CDATA[Olav]]></dc:creator>
		<pubDate>Sat, 17 Jul 2010 15:24:13 +0000</pubDate>
		<guid isPermaLink="false">http://thingsilearned.wordpress.com/?p=195#comment-820</guid>
		<description><![CDATA[Thanks a lot! I didn&#039;t think it was going to be this easy when i heard from the IRC guys there was no builtin subdomain support in Django.]]></description>
		<content:encoded><![CDATA[<p>Thanks a lot! I didn&#8217;t think it was going to be this easy when i heard from the IRC guys there was no builtin subdomain support in Django.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

