<?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>blog.timc3.com &#187; django</title>
	<atom:link href="http://blog.timc3.com/category/computing/django-computing/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.timc3.com</link>
	<description>providing news and views since 2003</description>
	<lastBuildDate>Thu, 02 Feb 2012 19:59:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<link rel="http://api.friendfeed.com/2008/03#sup" xmlns="http://www.w3.org/2005/Atom" type="application/json" href="http://friendfeed.com/api/public-sup.json#9e509d204d"/>		<item>
		<title>Django Select Multiple filter.</title>
		<link>http://blog.timc3.com/2010/11/02/django-select-multiple-filter/</link>
		<comments>http://blog.timc3.com/2010/11/02/django-select-multiple-filter/#comments</comments>
		<pubDate>Tue, 02 Nov 2010 16:33:28 +0000</pubDate>
		<dc:creator>timc3</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[Websites]]></category>

		<guid isPermaLink="false">http://blog.timc3.com/?p=829</guid>
		<description><![CDATA[Django has a really nice select multiple field, for choosing multiple items at once with a Javascript chooser.. It is really handy to use when there is a large number of items that have to be chosen from in a select. I am using with JQuery. To do this, grab SelectFilter2.js from the django-admin media [...]]]></description>
			<content:encoded><![CDATA[<p>Django has a really nice select multiple field, for choosing multiple items at once with a Javascript chooser..</p>
<p><a href="http://blog.timc3.com/wp-content/uploads/2010/11/django-admin-after.png"><img src="http://blog.timc3.com/wp-content/uploads/2010/11/django-admin-after-300x142.png" alt="" title="django-select-multiple" width="300" height="142" class="alignright size-medium wp-image-830" /></a></p>
<p>It is really handy to use when there is a large number of items that have to be chosen from in a select. I am using with JQuery.</p>
<p>To do this, grab SelectFilter2.js from the django-admin media folder, or get it from Django&#8217;s GitHub repository. Then to initialize it you can put the following into your code:</p>
<div class="codecolorer-container javascript vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; $.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;select[multiple]&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #006600; font-style: italic;">// &quot;Locations&quot; can be any label you want</span><br />
&nbsp; &nbsp; SelectFilter.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">id</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;Locations&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;/media/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>This will use the SelectFilter on all select multiples and give it a label of locations.</p>
<p>For reference the functions are:</p>
<div class="codecolorer-container javascript vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>field_id<span style="color: #339933;">,</span> field_name<span style="color: #339933;">,</span> is_stacked<span style="color: #339933;">,</span> admin_media_prefix<span style="color: #009900;">&#41;</span></div></div>
<p>So you could use:</p>
<div class="codecolorer-container javascript vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;SelectFilter.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#MySelect&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;Test&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;{{ MEDIA_URL}}img/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Then all that needs is styling the select multiple.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.timc3.com/2010/11/02/django-select-multiple-filter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django localization and internationalization</title>
		<link>http://blog.timc3.com/2010/10/19/django-localization-and-internationalization/</link>
		<comments>http://blog.timc3.com/2010/10/19/django-localization-and-internationalization/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 21:50:07 +0000</pubDate>
		<dc:creator>timc3</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[localization]]></category>

		<guid isPermaLink="false">http://blog.timc3.com/?p=826</guid>
		<description><![CDATA[We have been using the localization and internationalization ( l10n&#038; i18n ) from Django quite a bit for our translations, and although we haven&#8217;t had to tackle anything difficult like Arabic or Persian yet there are still some shortcomings in the system. The standard Django module for input of dates and datetime stamps is quite [...]]]></description>
			<content:encoded><![CDATA[<p>We have been using the localization and internationalization ( l10n&#038; i18n ) from Django quite a bit for our translations, and although we haven&#8217;t had to tackle anything difficult like Arabic or Persian yet there are still some shortcomings in the system.</p>
<p>The standard Django module for input of dates and datetime stamps is quite restrictive. It depends on a module, I think written by Simon Willson which uses the PHP notation rather than the Python/C strftime / strptime notation. Thus although its easy to display dates or datetime based upon the included locale files, parsing them is not so trivial from what I can see. To get around it, a configuration is placed to try and parse the date or datetime&#8217;s until a match is found. Looking at the code it does indeed use a try and except method of matching, mean potentially 10/10/10 could be any combination.</p>
<p>Secondly we use the JS18n/ url which outputs translations to be used by Javascript, but this is not in the form that the Javascript Date object can understand so one has to create a function to parse the datetime:</p>
<div class="codecolorer-container javascript vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">formats<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'DATETIME_FORMAT'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'N j, Y, P'</span><span style="color: #339933;">;</span></div></div>
<p>That can&#8217;t be understood by Javascript unless you do so.</p>
<p>Looks like there is some work to be done there, but mid-project is not the time to start making patches to code libraries.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.timc3.com/2010/10/19/django-localization-and-internationalization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django 1.2 release</title>
		<link>http://blog.timc3.com/2010/05/15/django-1-2-release/</link>
		<comments>http://blog.timc3.com/2010/05/15/django-1-2-release/#comments</comments>
		<pubDate>Sat, 15 May 2010 08:07:46 +0000</pubDate>
		<dc:creator>timc3</dc:creator>
				<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://blog.timc3.com/?p=801</guid>
		<description><![CDATA[It was just announced that Django 1.2 will be released on May 17th, which is in 3 days time. Been waiting a while for this one to go to production release so I am really glad. The new messages framework looks much better, and I also love the date i18n features &#8211; something that really [...]]]></description>
			<content:encoded><![CDATA[<p>It was just announced that Django 1.2 will be released on May 17th, which is in 3 days time.</p>
<p>Been waiting a while for this one to go to production release so I am really glad. The new messages framework looks much better, and I also love the date i18n features &#8211; something that really helps on a project at Cantemo where we have to deal with ISO formatted datetimes.</p>
<p>Now the users will be able to choose how their dates are displayed on individual systems.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.timc3.com/2010/05/15/django-1-2-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python plugin systems</title>
		<link>http://blog.timc3.com/2010/04/22/python-plugin-systems/</link>
		<comments>http://blog.timc3.com/2010/04/22/python-plugin-systems/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 11:01:17 +0000</pubDate>
		<dc:creator>timc3</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://blog.timc3.com/?p=788</guid>
		<description><![CDATA[There is a lot of interesting information about creating plugin architectures using Python all over the web, but its in fairly disparate places. This is an overview of the documentation that I found as of April 2010. Firstly Dr André Roberge has some very interesting posts, as well as a talk at PyCon 2009 on [...]]]></description>
			<content:encoded><![CDATA[<p>There is a lot of interesting information about creating plugin architectures using Python all over the web, but its in fairly disparate places. This is an overview of the documentation that I found as of April 2010.</p>
<p>Firstly <strong>Dr André Roberge</strong> has some very interesting posts, as well as a talk at PyCon 2009 on Blip.tv entitled <a href="http://blip.tv/file/1949302/">Plugins and monkeypatching: increasing flexibility, dealing with inflexibility</a>. He is also the author of Crunchy which uses a <a href="http://pytute.blogspot.com/2007/04/python-plugin-system.html">plugin system</a>. He goes on to write about his experiences in creating a plugin architecture on his blog, over 6 parts starting <a href="http://aroberge.blogspot.com/2008/12/plugins-part-1-application.html"> here  on part 1</a>.</p>
<p><strong>Marty Alchin</strong>, the author of Pro Django has an interesting couple of pages in that same book about creating a simple plugin system, and the snippet of code is on<a href="http://www.djangosnippets.org/snippets/542/"> djangosnippets.com</a>. He also has an excellent blog post about <a href="http://martyalchin.com/2008/jan/10/simple-plugin-framework/">implementing a plugin architecture</a>, it also talks about Django but is fairly non-specific.</p>
<p><strong>William E. Hart</strong> over 2009-2010 has also been researching Python Plugin Frameworks, <a href="http://wehart.blogspot.com/2009/01/python-plugin-frameworks.html">his overview is on his blog</a> and he is also the author of the <a href="http://pypi.python.org/pypi/pyutilib.component.doc/1.0.1"><strong>PyUtilib Component Architecture</strong></a>. This was very recently released and so hasn&#8217;t gathered much momentum as of this post but looks very promising indeed.</p>
<p><strong>Zope</strong>. The big one is the<a href="http://wiki.zope.org/zope3/ComponentArchitectureOverview"> Zope Component Architecture</a>. I must admit, that looking into it I think its overkill, I don&#8217;t like the configuration utility or the overhead it introduces &#8211; just to use it requires a lot of extra Zope modules. However google for it if you are interested in learning further.</p>
<p><strong>Yapsy.</strong> <a href="http://yapsy.sourceforge.net/">Yapsy</a> is interesting, looks extremely lightweight, has been around for a few years, is currently on version 1.7 and serves as a good starting point. It has no external dependancies.</p>
<p><strong>SprinklesPy</strong>. <a href="http://termie.pbworks.com/SprinklesPy">SprinklesPy</a> is also very lightweight but I am not sure that development is active on it (2006 was the last mention of it being used that I found), or that it has anyone in the community using it (a benefit I believe if you are implementing a system that you are not creating yourself.)</p>
<p><strong>Trac</strong> is the one component architecture that frequently gets mentioned, and it has a very decent user base. However, ripping the plugin system out might be more work than is reasonable. </p>
<p>Examples of Plugin use in the wild:</p>
<ul>
<li><a href="http://code.google.com/p/oohembed">http://code.google.com/p/oohembed</a></li>
</ul>
<p>Other interesting links:</p>
<ul>
<li><a href="http://www.charlesleifer.com/blog/looking-registration-patterns-django/">http://www.charlesleifer.com/blog/looking-registration-patterns-django/</a></li>
<li><a href="http://stackoverflow.com/questions/932069/building-a-minimal-plugin-architecture-in-python">Stackoverflow thread on minimal plugin architectures</a></li>
<li><a href="http://live.gnome.org/Gedit/PythonPluginHowTo">http://live.gnome.org/Gedit/PythonPluginHowTo</a></li>
</ul>
<p>It is clear to <a target="_self" href="mailto:tim@nospamplease.timc3.com">me</a> that there is no correct way of implementing plugins and you have to pick based upon the needs of your project, but this should serve as a good starting point. I will add and update this post as my knowledge grows.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.timc3.com/2010/04/22/python-plugin-systems/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Django on RedHat or CentOS</title>
		<link>http://blog.timc3.com/2010/03/26/django-on-redhat-or-centos/</link>
		<comments>http://blog.timc3.com/2010/03/26/django-on-redhat-or-centos/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 10:07:21 +0000</pubDate>
		<dc:creator>timc3</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[redhat]]></category>

		<guid isPermaLink="false">http://blog.timc3.com/?p=769</guid>
		<description><![CDATA[I am normally using Debian, Ubuntu or even Suse for deploying Django, but a recent customer needed to deploy on Red Hat Enterprise Server 5. We decided beforehand to test deployment on RHEL5 and also on CentOS 5.4 and so these instructions should work for both environments. NginX will be used as the webserver. The [...]]]></description>
			<content:encoded><![CDATA[<p>I am normally using <a target="_blank" href="http://www.debian.org">Debian</a>, Ubuntu or even Suse for deploying Django, but a recent customer needed to deploy on Red Hat Enterprise Server 5.</p>
<p>We decided beforehand to test deployment on RHEL5 and also on CentOS 5.4 and so these instructions should work for both environments. NginX will be used as the webserver.</p>
<p>The first thing I like to do is to upgrade the repository and add EPEL. This wasn&#8217;t needed I found on the RedHat box I was using, but was needed on CentOS but your mileage might vary. It should be noted that we made the system as up to date as possible with patches and yum updates.</p>
<p>I won&#8217;t be covering the database setup, it is assumed that this is already setup and done. I also won&#8217;t be covering the actually placing of the Django application anywhere.</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<br />
rpm <span style="color: #660033;">-Uvh</span> http:<span style="color: #000000; font-weight: bold;">//</span>download.fedora.redhat.com<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>epel<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">5</span><span style="color: #000000; font-weight: bold;">/</span>i386<span style="color: #000000; font-weight: bold;">/</span>epel-release-<span style="color: #000000;">5</span>-<span style="color: #000000;">3</span>.noarch.rpm<br />
<span style="color: #c20cb9; font-weight: bold;">yum</span> repolist<br />
<span style="color: #c20cb9; font-weight: bold;">yum update</span><br />
<span style="color: #c20cb9; font-weight: bold;">yum search</span> zlib<br />
<span style="color: #c20cb9; font-weight: bold;">yum install</span> zlib-devel<span style="color: #000000; font-weight: bold;">*</span><br />
<span style="color: #c20cb9; font-weight: bold;">yum install</span> <span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #c20cb9; font-weight: bold;">make</span></div></div>
<p>Python 2.4 ships with both RHEL5 and CentOS 5 and is needed for the packaging environment YUM so I would advise not to replace it but just compile and install 2.5.5 (or 2.6) next to it.</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> src<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> src<br />
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.python.org<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>python<span style="color: #000000; font-weight: bold;">/</span>2.5.5<span style="color: #000000; font-weight: bold;">/</span>Python-2.5.5.tgz<br />
<span style="color: #c20cb9; font-weight: bold;">tar</span> fxz Python-2.5.5.tgz<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> Python-2.5.5<br />
.<span style="color: #000000; font-weight: bold;">/</span>configure<br />
<span style="color: #c20cb9; font-weight: bold;">make</span><br />
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span><br />
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>src<br />
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>pypi.python.org<span style="color: #000000; font-weight: bold;">/</span>packages<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2.5</span><span style="color: #000000; font-weight: bold;">/</span>s<span style="color: #000000; font-weight: bold;">/</span>setuptools<span style="color: #000000; font-weight: bold;">/</span>setuptools-0.6c11-py2.5.egg<span style="color: #666666; font-style: italic;">#md5=64c94f3bf7a72a13ec83e0b24f2749b2</span><br />
<span style="color: #c20cb9; font-weight: bold;">sh</span> setuptools-0.6c11-py2.5.egg</div></div>
<p>Now we need to build and install NginX. I choose this primarily because of my experience with it, (I have used Apache2 a lot  but its archaic ) and because of its speed.</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">yum install</span> pcre-devel.i386 openssl-devel.i386<br />
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>nginx.org<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>nginx-0.7.65.tar.gz<br />
<span style="color: #c20cb9; font-weight: bold;">tar</span> fxz nginx-0.7.65.tar.gz<br />
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--sbin-path</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin <span style="color: #660033;">--conf-path</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>nginx.conf <span style="color: #660033;">--pid-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>nginx.pid <span style="color: #660033;">--error-log-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>error.log <span style="color: #660033;">--http-log-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>access.log --with-http_ssl_module --with-http_flv_module <span style="color: #660033;">--with-cc-opt</span>=<span style="color: #ff0000;">&quot;-I /usr/include/pcre&quot;</span> <br />
<span style="color: #c20cb9; font-weight: bold;">make</span><br />
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span><br />
<span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nginx<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nginx<br />
<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>chkconfig nginx on<br />
<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>chkconfig <span style="color: #660033;">--list</span> nginx</div></div>
<p>There is a decent RedHat init.d script here: <a href="http://wiki.nginx.org/RedHatNginxInitScript">http://wiki.nginx.org/RedHatNginxInitScript</a>, but remember that I have changed the installation location above so you will need to change the location in that script of nginx from /usr/sbin/nginx to /usr/local/sbin/nginx</p>
<p>You will also need a nginx.conf configuration script for /etc/nginx/ or you could roll your own using sites-available, sites-enabled pattern.  I will attach the script soon.</p>
<p>Now with Python 2.5 installed we can install Django and other requirements:</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">easy_install-<span style="color: #000000;">2.5</span> Django<br />
easy_install-<span style="color: #000000;">2.5</span> django-nose<br />
easy_install-<span style="color: #000000;">2.5</span> http:<span style="color: #000000; font-weight: bold;">//</span>dist.repoze.org<span style="color: #000000; font-weight: bold;">/</span>PIL-1.1.6.tar.gz<br />
easy_install-<span style="color: #000000;">2.5</span> flup</div></div>
<p>I am using easy_install here as that is the most widely used tool, but pip with a requirements file is a better solution.</p>
<p>Now we need a database adapter. I am using PostgreSQL 8.4.2, if you are using MySQL, Oracle or some other database you will need to follow the recommended route for the Python adapter.</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">yum search</span> psycopg2<br />
<span style="color: #c20cb9; font-weight: bold;">yum install</span> python-psycopg2.i386 <span style="color: #7a0874; font-weight: bold;">&#40;</span>This will <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #000000; font-weight: bold;">for</span> the old Python<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #c20cb9; font-weight: bold;">yum install</span> postgresql-devel<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>src<br />
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>initd.org<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>software<span style="color: #000000; font-weight: bold;">/</span>psycopg<span style="color: #000000; font-weight: bold;">/</span>psycopg2-2.0.13.tar.gz<br />
<span style="color: #c20cb9; font-weight: bold;">tar</span> xvfz psycopg2-2.0.13.tar.gz<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> psycopg2-2.0.13<br />
<span style="color: #c20cb9; font-weight: bold;">vim</span> setup.cfg</div></div>
<p>Change the location of pg_config:</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp;<span style="color: #007800;">pg_config</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pg_config</div></div>
<p>And now install:</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">python2.5 setup.py build<br />
python2.5 setup.py <span style="color: #c20cb9; font-weight: bold;">install</span></div></div>
<p>Then you need to install your application. This is really specific to your needs. I choose to install the files in /opt/cantemo/application-name as that is specific to our solutions, but RedHat style might mean that you wish to install somewhere else.</p>
<p>Lastly you will want to have your application start easily and also make sure that it starts if the machine ever reboots. To do this I am going to install the start-stop-daemon that is used on <a target="_blank" href="http://www.debian.org">Debian</a> based <a target="_blank" href="http://www.debian.org">Linux</a> distros on Redhat. I read some threads that it will but there is no ETA on that.</p>
<p>You should download the initd script for Django from <a href="http://code.djangoproject.com/wiki/InitdScriptForLinux">http://code.djangoproject.com/wiki/InitdScriptForLinux</a>. Change the RUN_AS user to the user on RedHat that you are going to use for running Nginx. By default this is apache.</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>src<br />
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>developer.axis.com<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>distribution<span style="color: #000000; font-weight: bold;">/</span>apps-sys-utils-start-stop-daemon-IR1_9_18-<span style="color: #000000;">2</span>.tar.gz<br />
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xzf</span> apps-sys-utils-start-stop-daemon-IR1_9_18-<span style="color: #000000;">2</span>.tar.gz<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>sys-utils<span style="color: #000000; font-weight: bold;">/</span>start-stop-daemon-IR1_9_18-<span style="color: #000000;">2</span><br />
<span style="color: #c20cb9; font-weight: bold;">gcc</span> start-stop-daemon.c <span style="color: #660033;">-o</span> start-stop-daemon<br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> start-stop-daemon <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>start-stop-daemon<br />
<span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.id<span style="color: #000000; font-weight: bold;">/</span>fastcgi<br />
<span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>fastcgi<br />
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>fastcgi start<br />
<span style="color: #c20cb9; font-weight: bold;">ps</span> ax<br />
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>fastcgi stop<br />
<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>chkconfig <span style="color: #660033;">--add</span> fastcgi<br />
<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>chkconfig <span style="color: #660033;">--list</span> fastcgi</div></div>
<p>Lastly make sure that your application directories have the correct user permissions but you should be able to start everything by issuing the following commands:</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nginx start<br />
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>fastcgi start</div></div>
<p>Eric Florenzano posted a nice tutorial on <a href="http://djangoadvent.com/1.2/deploying-django-site-using-fastcgi/">deploying django using FastCGI</a> so also check that out, but I didn&#8217;t have much luck with daemontools on CentOS, and didn&#8217;t bother trying on RedHat. I suggest instead using start-stop-daemon. Check it out for other hints and tips though, particularly on prefork vs. threaded, pip, and more nginx configuration tips.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.timc3.com/2010/03/26/django-on-redhat-or-centos/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Django staff member required</title>
		<link>http://blog.timc3.com/2010/03/13/django-staff-member-required/</link>
		<comments>http://blog.timc3.com/2010/03/13/django-staff-member-required/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 09:30:50 +0000</pubDate>
		<dc:creator>timc3</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://blog.timc3.com/?p=734</guid>
		<description><![CDATA[Here is a simple decorator that isn&#8217;t mentioned properly in the Django documentation. @staff_member_required It basically checks to see if the user is logged in and has is_staff before allowing a user access to the view. Use like you would the normal @login_required decorator. from django.shortcuts import render_to_response from django.template.context import RequestContext from django.contrib.admin.views.decorators import [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple decorator that isn&#8217;t mentioned properly in the Django documentation.</p>
<div class="codecolorer-container python vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">@</span>staff_member_required</div></div>
<p>It basically checks to see if the user is logged in and has is_staff before allowing a user access to the view. Use like you would the normal<br />
@login_required decorator.</p>
<div class="codecolorer-container python vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">shortcuts</span> <span style="color: #ff7700;font-weight:bold;">import</span> render_to_response<br />
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">template</span>.<span style="color: black;">context</span> <span style="color: #ff7700;font-weight:bold;">import</span> RequestContext<br />
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span>.<span style="color: black;">admin</span>.<span style="color: black;">views</span>.<span style="color: black;">decorators</span> <span style="color: #ff7700;font-weight:bold;">import</span> staff_member_required<br />
<br />
<br />
<span style="color: #66cc66;">@</span>staff_member_required<br />
<span style="color: #ff7700;font-weight:bold;">def</span> my_view<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> render_to_response<span style="color: black;">&#40;</span><span style="color: #483d8b;">'page.html'</span><span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context_instance<span style="color: #66cc66;">=</span>RequestContext<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.timc3.com/2010/03/13/django-staff-member-required/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extending Django&#8217;s user admin</title>
		<link>http://blog.timc3.com/2010/02/18/extending-djangos-user-admin/</link>
		<comments>http://blog.timc3.com/2010/02/18/extending-djangos-user-admin/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 22:06:23 +0000</pubDate>
		<dc:creator>timc3</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://blog.timc3.com/?p=732</guid>
		<description><![CDATA[The built in admin pages that you get in Django can be useful, but they particularly become useful once you start to add a lot more functionality to them. For instance the Django&#8217;s User authentication system (which lives in django.contrib.auth ) is widely used, and quite often you need to extend the user&#8217;s profile by [...]]]></description>
			<content:encoded><![CDATA[<p>The built in admin pages that you get in Django can be useful, but they particularly become useful once you start to add a lot more functionality to them.</p>
<p>For instance the Django&#8217;s User authentication system (which lives in django.contrib.auth ) is widely used, and quite often you need to extend the user&#8217;s profile by using AUTH_PROFILE_MODULE and a separate model. But having a separate Admin screen for this is kind of pointless.</p>
<p>In the admin.py file for your model which provides extra information (in my example it is called UserProfile just do the following:</p>
<div class="codecolorer-container python vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span> <span style="color: #ff7700;font-weight:bold;">import</span> admin<br />
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span>.<span style="color: black;">auth</span>.<span style="color: black;">admin</span> <span style="color: #ff7700;font-weight:bold;">import</span> UserAdmin<br />
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span>.<span style="color: black;">auth</span>.<span style="color: black;">models</span> <span style="color: #ff7700;font-weight:bold;">import</span> User<br />
<span style="color: #ff7700;font-weight:bold;">from</span> models <span style="color: #ff7700;font-weight:bold;">import</span> UserProfile<br />
<br />
<span style="color: #ff7700;font-weight:bold;">class</span> UserProfileInline<span style="color: black;">&#40;</span>admin.<span style="color: black;">TabularInline</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; model <span style="color: #66cc66;">=</span> UserProfile<br />
&nbsp; &nbsp; fk_name <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'user'</span><br />
&nbsp; &nbsp; max_num <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; <br />
<span style="color: #ff7700;font-weight:bold;">class</span> CustomUserAdmin<span style="color: black;">&#40;</span>UserAdmin<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; inlines <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span>UserProfileInline<span style="color: #66cc66;">,</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; list_display <span style="color: #66cc66;">=</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">'username'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'email'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'first_name'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'last_name'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'is_staff'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'is_active'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <br />
admin.<span style="color: #dc143c;">site</span>.<span style="color: black;">unregister</span><span style="color: black;">&#40;</span>User<span style="color: black;">&#41;</span><br />
admin.<span style="color: #dc143c;">site</span>.<span style="color: black;">register</span><span style="color: black;">&#40;</span>User<span style="color: #66cc66;">,</span> CustomUserAdmin<span style="color: black;">&#41;</span></div></div>
<p>Simple once you know how.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.timc3.com/2010/02/18/extending-djangos-user-admin/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>gcc and python</title>
		<link>http://blog.timc3.com/2010/02/18/gcc-and-python/</link>
		<comments>http://blog.timc3.com/2010/02/18/gcc-and-python/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 14:18:14 +0000</pubDate>
		<dc:creator>timc3</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://blog.timc3.com/?p=730</guid>
		<description><![CDATA[Had an interesting little problem with gcc and python today on OS X 10.6. Basically I was trying to use graphviz and pygraphviz, and installing from source I got messages like this: gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -I/usr/local/include/graphviz -I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c pygraphviz/graphviz_wrap.c -o build/temp.macosx-10.3-i386-2.5/pygraphviz/graphviz_wrap.o cc1: [...]]]></description>
			<content:encoded><![CDATA[<p>Had an interesting little problem with gcc and python today on OS X 10.6.</p>
<p>Basically I was trying to use graphviz and pygraphviz, and installing from source I got messages like this:</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-arch</span> ppc <span style="color: #660033;">-arch</span> i386 <span style="color: #660033;">-isysroot</span> <span style="color: #000000; font-weight: bold;">/</span>Developer<span style="color: #000000; font-weight: bold;">/</span>SDKs<span style="color: #000000; font-weight: bold;">/</span>MacOSX10.4u.sdk <span style="color: #660033;">-fno-strict-aliasing</span> <span style="color: #660033;">-Wno-long-double</span> <span style="color: #660033;">-no-cpp-precomp</span> <span style="color: #660033;">-mno-fused-madd</span> <span style="color: #660033;">-fno-common</span> <span style="color: #660033;">-dynamic</span> <span style="color: #660033;">-DNDEBUG</span> <span style="color: #660033;">-g</span> <span style="color: #660033;">-O3</span> -I<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>graphviz -I<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Frameworks<span style="color: #000000; font-weight: bold;">/</span>Python.framework<span style="color: #000000; font-weight: bold;">/</span>Versions<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2.5</span><span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>python2.5 <span style="color: #660033;">-c</span> pygraphviz<span style="color: #000000; font-weight: bold;">/</span>graphviz_wrap.c <span style="color: #660033;">-o</span> build<span style="color: #000000; font-weight: bold;">/</span>temp.macosx-<span style="color: #000000;">10.3</span>-i386-<span style="color: #000000;">2.5</span><span style="color: #000000; font-weight: bold;">/</span>pygraphviz<span style="color: #000000; font-weight: bold;">/</span>graphviz_wrap.o<br />
cc1: error: unrecognized <span style="color: #7a0874; font-weight: bold;">command</span> line option <span style="color: #ff0000;">&quot;-Wno-long-double&quot;</span><br />
cc1: error: unrecognized <span style="color: #7a0874; font-weight: bold;">command</span> line option <span style="color: #ff0000;">&quot;-Wno-long-double&quot;</span><br />
lipo: can<span style="color: #ff0000;">'t figure out the architecture type of: /var/tmp//ccD4Ow7T.out<br />
error: command '</span><span style="color: #c20cb9; font-weight: bold;">gcc</span><span style="color: #ff0000;">' failed with exit status 1</span></div></div>
<p>This pointed to two problems I found:</p>
<ol>
<li>MacOSX10.4u.sdk being used</li>
<li> &#8220;-Wno-long-double&#8221; being passed to gcc</li>
</ol>
<p>Obviously I am on 10.6 and even though I do have that SDK installed it is the incorrect version. On some Xcode installations you won&#8217;t have it.</p>
<p>The remedy was to change the following file:</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Frameworks<span style="color: #000000; font-weight: bold;">/</span>Python.framework<span style="color: #000000; font-weight: bold;">/</span>Versions<span style="color: #000000; font-weight: bold;">/</span>Current<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>python2.5<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span>Makefile</div></div>
<p>After backing up change all the instances of MacOSX10.4u.sdk to MacOSX10.6.sdk and then remove the flag -Wno-long-double</p>
<p>Then you should be able to compile from a normal python setup. For good measure I test easy_install as well and that worked smoothly..</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.timc3.com/2010/02/18/gcc-and-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Django settings in template</title>
		<link>http://blog.timc3.com/2010/01/22/django-settings-in-template/</link>
		<comments>http://blog.timc3.com/2010/01/22/django-settings-in-template/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 10:51:18 +0000</pubDate>
		<dc:creator>timc3</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://blog.timc3.com/?p=723</guid>
		<description><![CDATA[So what do you do if you require a django setting in your templates, much like we have MEDIA_URL today? Well there are use cases for this, (if you are in doubt have a look at the original ticket for adding MEDIA_URL to django ). The easiest way that I have found so far is [...]]]></description>
			<content:encoded><![CDATA[<p>So what do you do if you require a django setting in your templates, much like we have MEDIA_URL today?</p>
<p>Well there are use cases for this, (if you are in doubt have a look at the original ticket for <a href="http://code.djangoproject.com/ticket/1278">adding MEDIA_URL to django</a> ).</p>
<p>The easiest way that I have found so far is to write a context processor. For example in my settings I might have JAVASCRIPT_URL (which in my real life code changes depending on whether I am running in debug, test or from a CDN):</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">JAVASCRIPT_URL = 'http://myjshost.com'</div></div>
<p>Now from here I would like to make this available in my templates. Create a new python file that is somewhere on your python path (Under my project, I create a utils directory and then put a file context_processors.py in there. Don&#8217;t forget __init__.py should live in that directory as well).</p>
<p>In the context_processors.py file simply put</p>
<div class="codecolorer-container python vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">def</span> javascript_url<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">conf</span> <span style="color: #ff7700;font-weight:bold;">import</span> settings<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#123;</span><span style="color: #483d8b;">'JAVASCRIPT_URL'</span>: settings.<span style="color: black;">JAVASCRIPT_URL</span><span style="color: black;">&#125;</span></div></div>
<p>In your settings.py file you might already have a reference to TEMPLATE_CONTEXT_PROCESSORS if not then add it like so:</p>
<div class="codecolorer-container python vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">conf</span>.<span style="color: black;">global_settings</span> <span style="color: #ff7700;font-weight:bold;">import</span> TEMPLATE_CONTEXT_PROCESSORS<br />
TEMPLATE_CONTEXT_PROCESSORS +<span style="color: #66cc66;">=</span> <span style="color: black;">&#40;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'django.core.context_processors.request'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'django.core.context_processors.i18n'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'appname.utils.context_processors.javascript_url'</span><span style="color: #66cc66;">,</span><br />
<span style="color: black;">&#41;</span></div></div>
<p>And thats about it. From there on in you will be able to use JAVASCRIPT_URL like MEDIA_URL:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">{{ JAVASCRIPT_URL }}</div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.timc3.com/2010/01/22/django-settings-in-template/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Leading zeros in django</title>
		<link>http://blog.timc3.com/2009/07/13/leading-zeros-in-django/</link>
		<comments>http://blog.timc3.com/2009/07/13/leading-zeros-in-django/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 11:28:55 +0000</pubDate>
		<dc:creator>timc3</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://blog.timc3.com/?p=654</guid>
		<description><![CDATA[I am always forgetting about the stringformatting tag in Django&#8217;s templating language. For instance for leading zeros: {{ variable&#124;stringformat:&#34;02d&#34; }} This will always put a leading zero.]]></description>
			<content:encoded><![CDATA[<p>I am always forgetting about the stringformatting tag in Django&#8217;s templating language. For instance for leading zeros:</p>
<div class="codecolorer-container html4strict vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">{{ variable|stringformat:&quot;02d&quot; }}</div></div>
<p>This will always put a leading zero.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.timc3.com/2009/07/13/leading-zeros-in-django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 21/79 queries in 1.389 seconds using disk: basic
Object Caching 1479/1592 objects using disk: basic

Served from: blog.timc3.com @ 2012-02-10 10:00:13 -->
