<?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>Red Robot Studios &#187; Scott Barnham</title>
	<atom:link href="http://www.redrobotstudios.com/blog/author/sgb/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.redrobotstudios.com/blog</link>
	<description>Web development company specialising in Django and mobile development for clients around the world</description>
	<lastBuildDate>Fri, 30 Dec 2011 12:51:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>Finding your nearest Diet Club</title>
		<link>http://www.redrobotstudios.com/blog/2011/04/07/finding-your-nearest-diet-club/</link>
		<comments>http://www.redrobotstudios.com/blog/2011/04/07/finding-your-nearest-diet-club/#comments</comments>
		<pubDate>Thu, 07 Apr 2011 21:52:00 +0000</pubDate>
		<dc:creator>Scott Barnham</dc:creator>
				<category><![CDATA[portfolio]]></category>

		<guid isPermaLink="false">http://www.redrobotstudios.com/blog/?p=267</guid>
		<description><![CDATA[A few months ago we developed a simple proximity search or &#8220;find your nearest&#8221; site for online marketing consultants OLCM.  The site helps you find the nearest diet class from clubs like Weight Watchers and Rosemary Conley.

I&#8217;m pretty happy with the project.  It was done in a short time and reasonable budget, but [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago we developed a simple proximity search or &#8220;find your nearest&#8221; site for <a href="http://www.olcm.co.uk/">online marketing consultants</a> OLCM.  The site helps you find the nearest <a href="http://dietclass.co.uk/">diet class</a> from clubs like Weight Watchers and Rosemary Conley.</p>
<p><a href="http://www.redrobotstudios.com/blog/wp-content/uploads/2011/04/dietclass-shot.png"><img src="http://www.redrobotstudios.com/blog/wp-content/uploads/2011/04/dietclass-shot.png" alt="" title="dietclass-shot" width="95%" class="aligncenter size-full wp-image-268" /></a></p>
<p>I&#8217;m pretty happy with the project.  It was done in a short time and reasonable budget, but made to be reusable across different niches.</p>
<p>We used Django with some customisations to admin so that data can be uploaded from csv files.  The proximity search uses a postcode-to-lat/lng database for when a postcode is entered and geocoding from Google Maps when a place name is entered.</p>
<p>The site is proving popular so far and we hope it will be a great success.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redrobotstudios.com/blog/2011/04/07/finding-your-nearest-diet-club/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using images for background text</title>
		<link>http://www.redrobotstudios.com/blog/2011/02/07/using-images-for-background-text/</link>
		<comments>http://www.redrobotstudios.com/blog/2011/02/07/using-images-for-background-text/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 10:47:42 +0000</pubDate>
		<dc:creator>Scott Barnham</dc:creator>
				<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.redrobotstudios.com/blog/?p=244</guid>
		<description><![CDATA[Background text: What to type in the field
It&#8217;s very common to use &#8216;background text&#8217; in form fields to indicate what should be typed in there.  For example, &#8216;name&#8217; and &#8216;email&#8217; in grey text means you should type your, um, name and email address, in to those fields.
The normal way to do it is put [...]]]></description>
			<content:encoded><![CDATA[<h3>Background text: What to type in the field</h3>
<p>It&#8217;s very common to use &#8216;background text&#8217; in form fields to indicate what should be typed in there.  For example, &#8216;name&#8217; and &#8216;email&#8217; in grey text means you should type your, um, name and email address, in to those fields.</p>
<p>The normal way to do it is put text in the fields, set the colour to grey using css and then remove it when the user clicks in that field.  It just takes a couple of lines of JavaScript.</p>
<p>But what happens if you want text in a search field, or other field that you want to set the focus on when the page loads?</p>
<h3>Background images so the field can have focus</h3>
<p>An alternative I&#8217;ve used a few times is to have an image containing the grey text and show that image whenever there is no text in the field, regardless of whether the field has focus.</p>
<p>Here&#8217;s an example from <a href="http://ticktocktaxi.co.uk">London taxi booking</a> site Tick Tock Taxi:</p>
<p><img src="http://www.redrobotstudios.com/blog/wp-content/uploads/2011/02/backtext-place.png" alt="" title="backtext-taxi" width="95%" class="aligncenter size-full wp-image-245" /></p>
<p>The &#8220;<em>address, postcode or place of interest</em>&#8221; text is a background image and the focus is in that field when the page loads.  As soon as the user types something, the image is hidden.  If they delete all text from the field, the background image comes back.</p>
<p>A fancier example is from <a href="http://www.whoishostingthis.com/">hosting reviews site</a> WhoIsHostingThis.com:</p>
<p><img src="http://www.redrobotstudios.com/blog/wp-content/uploads/2011/02/backtext-wiht.png" alt="" title="backtext-wiht" width="95%" class="aligncenter size-full wp-image-249" /></p>
<p>Here the text is typed in after &#8216;<em>http://</em>&#8216;, so we actually swap between two background images &#8211; one with just &#8216;<em>http://</em>&#8216; and one which also has the arrow and &#8216;<em>Enter the domain here</em>&#8216;.  It shows an advantage to using images &#8211; you can put arrows and other graphics to better explain or draw attention to the field.</p>
<p>Here&#8217;s some code.</p>
<h4>jQuery:</h4>
<pre>BackImage = function(field) {
    field = $(field);
    field.bind('keyup', function(e){
        field.toggleClass('empty', field.val() == '');
    });
}

new BackImage('#search_field');</pre>
<h4>MooTools:</h4>
<pre>var BackImage = new Class({
    initialize: function(field) {
        this.field = field;
        field.addEvent('keyup', this.update.bind(this));
        this.update();
    },
    update: function() {
        this.field.toggleClass('empty', this.field.get('value') == '');
    }
});

new BackImage($('search_field'));</pre>
<h4>CSS</h4>
<p>The css just sets a background image when the field has class &#8216;empty&#8217;.</p>
<pre>#search_field.empty {background:#fff url(../images/bg-search-empty.png) no-repeat 5px center;}</pre>
<p>That&#8217;s it, a simple technique to have background text while allowing the field to have focus.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redrobotstudios.com/blog/2011/02/07/using-images-for-background-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobile ticketing from TicketSense</title>
		<link>http://www.redrobotstudios.com/blog/2011/02/01/mobile-ticketing-from-ticketsense/</link>
		<comments>http://www.redrobotstudios.com/blog/2011/02/01/mobile-ticketing-from-ticketsense/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 11:10:40 +0000</pubDate>
		<dc:creator>Scott Barnham</dc:creator>
				<category><![CDATA[portfolio]]></category>

		<guid isPermaLink="false">http://www.redrobotstudios.com/blog/?p=238</guid>
		<description><![CDATA[It&#8217;s always nice to see innovation in an established industry.  Selling tickets for events hasn&#8217;t changed much until recently when the web and mobile phones made it cheaper and easier to sell tickets directly to customers.
TicketSense is a UK company which helps event organisers and venues sell tickets direct to customers&#8217; mobile phones.  [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s always nice to see innovation in an established industry.  Selling tickets for events hasn&#8217;t changed much until recently when the web and mobile phones made it cheaper and easier to sell tickets directly to customers.</p>
<p><a href="http://www.ticketsense.co.uk/">TicketSense</a> is a UK company which helps event organisers and venues sell tickets direct to customers&#8217; mobile phones.  It&#8217;s automated and pretty slick: Customers text a keyword like &#8216;thewho&#8217; to a special number to buy a ticket.  They can pay by credit card, PayPal, or on their phone bill.  The ticket is sent to them as an SMS text message with a barcode image attached  &#8211; no need to print and distribute paper tickets.</p>
<p><a href="http://www.ticketsense.co.uk/"><img src="http://www.redrobotstudios.com/blog/wp-content/uploads/2011/02/ticketsense-brand.png" alt="" title="ticketsense" width="75%" class="aligncenter size-full wp-image-239" /></a></p>
<p>When the customer gets to the <a href="http://www.ticketsense.co.uk/box_office">gig/event</a>, they show the barcode on the screen of their phone and the door staff scans it with a barcode scanner.</p>
<p>We helped TicketSense by developing a barcode scanning app for Windows and Mac OS X which integrates with their ticketing backend.  Door staff or event managers download the list of tickets sold, then scan them at the door, which checks them against the list.</p>
<p>We made the app simple to use with an obvious interface that&#8217;s easy to read in low-light conditions.  We developed using XULRunner to make a single cross-platform application.</p>
<p>The guys at TicketSense knew what they wanted and were a pleasure to work with.  We got some great feedback from them about the quality of our work and responsiveness.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redrobotstudios.com/blog/2011/02/01/mobile-ticketing-from-ticketsense/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>London Taxi Quotes and Bookings</title>
		<link>http://www.redrobotstudios.com/blog/2010/08/09/london-taxi-quotes-and-bookings/</link>
		<comments>http://www.redrobotstudios.com/blog/2010/08/09/london-taxi-quotes-and-bookings/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 11:25:39 +0000</pubDate>
		<dc:creator>Scott Barnham</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[portfolio]]></category>

		<guid isPermaLink="false">http://www.redrobotstudios.com/blog/?p=227</guid>
		<description><![CDATA[If you&#8217;re looking for a taxi in London, check out Tick Tock Taxi, the new taxi booking site recently launched by our friends at mochii.
Instant Fare Quote
Enter the address you&#8217;re at and where you want to go and the site gives you an instant quote for a mini-cab.  Booking is easy, just enter your [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re looking for a <a href="http://ticktocktaxi.co.uk/">taxi in London</a>, check out <em>Tick Tock Taxi</em>, the new taxi booking site recently launched by our friends at <a href="http://mochii.co.uk/">mochii</a>.</p>
<h3>Instant Fare Quote</h3>
<p>Enter the address you&#8217;re at and where you want to go and the site gives you an instant quote for a mini-cab.  Booking is easy, just enter your name and phone number.</p>
<p><a href="http://www.redrobotstudios.com/blog/wp-content/uploads/2010/08/ttt-shot.png"><img class="aligncenter size-full wp-image-228" src="http://www.redrobotstudios.com/blog/wp-content/uploads/2010/08/ttt-shot.png" alt="Tick Tock Taxi" width="600" height="545" /></a></p>
<p>Behind the scenes, there&#8217;s a database of cab companies, the nearest of which is notified and will contact you within minutes.  It&#8217;s a simple and painless way to find the cost and book your taxi.  There&#8217;s a <a href="http://ticktocktaxi.co.uk/mobile/">mobile version</a> under development, too.</p>
<h3>Fun Project</h3>
<p>We did the web programming for the site using Django.  It integrates with Google Maps for the address lookups (geocoding) and to find the distance by road for the fare calculation (using Google Maps directions).  It uses an SMS gateway to send text messages to customers and taxi companies.</p>
<p><em>Tick Tock Taxi</em> was conceived by mochii who also provided the design work.  They called us in to do the web development side and we&#8217;re happy to be involved.</p>
<p>Do you have an innovative website, web-based or mobile app?  <a href="http://www.redrobotstudios.com/contact/">Get in contact</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redrobotstudios.com/blog/2010/08/09/london-taxi-quotes-and-bookings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Data Filtering for WhoIsHostingThis.com</title>
		<link>http://www.redrobotstudios.com/blog/2010/07/14/dynamic-data-filtering-for-whoishostingthis/</link>
		<comments>http://www.redrobotstudios.com/blog/2010/07/14/dynamic-data-filtering-for-whoishostingthis/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 09:12:13 +0000</pubDate>
		<dc:creator>Scott Barnham</dc:creator>
				<category><![CDATA[portfolio]]></category>

		<guid isPermaLink="false">http://www.redrobotstudios.com/blog/?p=213</guid>
		<description><![CDATA[We&#8217;ve worked on the WhoIsHostingThis.com site for several years, since it was taken over by web marketing experts Quality Nonsense.  It started as a tool to tell you which web hosting company is hosting any site, but has changed and expanded in scope and usefulness, adding honest reviews and special offer hosting coupons over [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve worked on the WhoIsHostingThis.com site for several years, since it was taken over by web marketing experts <a href="http://www.qualitynonsense.com/">Quality Nonsense</a>.  It started as a tool to tell you which web hosting company is hosting any site, but has changed and expanded in scope and usefulness, adding <a href="http://www.whoishostingthis.com/about-our-reviews/">honest reviews</a> and special offer <a href="http://www.whoishostingthis.com/hosting-coupons/">hosting coupons</a> over the last couple of years.</p>
<h3>Hosting Comparison Tool</h3>
<p>A few months ago we helped launch the new <a href="http://www.whoishostingthis.com/hosting-reviews/">hosting comparison</a> tool which filters tens of thousands of data points to tell you which web hosting company is best for you.  Our role was to develop the comparison engine and super-slick dynamic interface which updates the list of suitable hosts as you click features and criteria that are important to you.</p>
<p><a href="http://www.redrobotstudios.com/blog/wp-content/uploads/2010/07/wiht-comparison.png"><img class="aligncenter size-full wp-image-216" title="web hosting comparison" src="http://www.redrobotstudios.com/blog/wp-content/uploads/2010/07/wiht-comparison.png" alt="" width="600" height="340" /></a></p>
<h3>Data Update Interface</h3>
<p>Behind the scenes, the team at WhoIsHostingThis.com add web hosting plans and regularly update masses of data using an interface we developed.  All changes are logged, checked and approved before going live on the site.</p>
<h3>Tech</h3>
<p>The WhoIsHostingThis.com site uses PHP and MySQL.  Much of the work for the hosting comparison tool was client-side, using JavaScript and the MooTools library.  The filter uses ajax to update the list of hosts without reloading the page making it quick and simple to compare and contrast hosts.</p>
<h3>Job Done</h3>
<p>WhoIsHostingThis.com is probably the largest site we regularly work on and Quality Nonsense is a great client.  We&#8217;re happy with the work we&#8217;ve done and it has been well received by testers and reviewers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redrobotstudios.com/blog/2010/07/14/dynamic-data-filtering-for-whoishostingthis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t delete an image file when deleting a Django model instance</title>
		<link>http://www.redrobotstudios.com/blog/2010/03/02/dont-delete-image-file-when-deleting-django-model-instance/</link>
		<comments>http://www.redrobotstudios.com/blog/2010/03/02/dont-delete-image-file-when-deleting-django-model-instance/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 09:54:22 +0000</pubDate>
		<dc:creator>Scott Barnham</dc:creator>
				<category><![CDATA[Django]]></category>

		<guid isPermaLink="false">http://www.redrobotstudios.com/blog/?p=55</guid>
		<description><![CDATA[If you have a Django model with a FileField or ImageField, when you delete the model instance, the associated file or image is also deleted.  In most cases this is desirable and keeps things tidy, but I had a situation recently where the image file should not be deleted when the model was deleted. [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a Django model with a <code>FileField</code> or <code>ImageField</code>, when you delete the model instance, the associated file or image is also deleted.  In most cases this is desirable and keeps things tidy, but I had a situation recently where the image file should not be deleted when the model was deleted.  Here&#8217;s a simple way to override the default behaviour.</p>
<h3>Custom file storage</h3>
<p>Django uses storage classes to determine how files are read and written.  Normally, the data is just written as files to disk, but there are other possibilities such as storing on remote servers.</p>
<p>It&#8217;s easy to write a <a href="http://docs.djangoproject.com/en/dev/howto/custom-file-storage/">custom file storage</a> class to override the behaviour of the default <code>FileStorageSystem</code>.  In this case, we only need to change the <code>delete</code> method so it does not delete the file.</p>
<p>In custom.py</p>
<pre>from django.core.files import storage

class NoDeleteFileStorage(storage.FileSystemStorage):
    def delete(self, name):
        pass</pre>
<p>We can then <a href="http://docs.djangoproject.com/en/1.1/topics/files/#file-storage">use the custom file storage</a> by making an instance and passing it to the <code>ImageField</code>.</p>
<p>In models.py</p>
<pre>from custom import NoDeleteFileStorage

ndfs = NoDeleteFileStorage()

class ImageInstance(models.Model):
    image = models.ImageField(storage=ndfs, ...)</pre>
<p>It&#8217;s as simple as that!  Custom file storage has some interesting possibilities.  With it you can handle how files are named or integrate with some caching or <a href="http://en.wikipedia.org/wiki/Content_Delivery_Network">CDN</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redrobotstudios.com/blog/2010/03/02/dont-delete-image-file-when-deleting-django-model-instance/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Custom web, Django and mobile development</title>
		<link>http://www.redrobotstudios.com/blog/2010/02/08/custom-web-django-and-mobile-development/</link>
		<comments>http://www.redrobotstudios.com/blog/2010/02/08/custom-web-django-and-mobile-development/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 10:04:15 +0000</pubDate>
		<dc:creator>Scott Barnham</dc:creator>
				<category><![CDATA[Company]]></category>
		<category><![CDATA[services]]></category>

		<guid isPermaLink="false">http://www.redrobotstudios.com/blog/?p=50</guid>
		<description><![CDATA[We started Red Robot Studios in 2008 to develop web-based apps using great technologies like Django. Since then we&#8217;ve learned an enormous amount about what it takes to build and deploy large-scale web applications, and as we&#8217;ve developed and released our own sites and apps, we&#8217;ve increasingly been approached by people who want us to work with [...]]]></description>
			<content:encoded><![CDATA[<p>We started Red Robot Studios in 2008 to develop web-based apps using great technologies like Django. Since then we&#8217;ve learned an enormous amount about what it takes to build and deploy large-scale web applications, and as we&#8217;ve developed and released our own sites and apps, we&#8217;ve increasingly been approached by people who want us to work with them to help them build great sites and services.</p>
<p>We&#8217;re still going to be building and releasing our own projects but have also decided to offer our development service to clients as well. We have some excellent clients already and will be accepting work from new clients.</p>
<p>Our aim is not just to provide a normal development service but to help our clients achieve their goals. We want to help and advise based on our experience and go the extra mile to provide <strong>really great</strong> development services to all our clients.</p>
<p>Our main focus is <a href="http://www.redrobotstudios.com/django-development/">Django development</a>, <a href="http://www.redrobotstudios.com/mobile-development/">iPhone and mobile development</a>, but we are well experienced in many other areas including things as diverse as WordPress plugins, Facebook apps and Firefox extensions. We&#8217;d love to hear about your great idea, so <a href="http://www.redrobotstudios.com/contact/">get in touch</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redrobotstudios.com/blog/2010/02/08/custom-web-django-and-mobile-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Requiring https for certain paths in Django</title>
		<link>http://www.redrobotstudios.com/blog/2010/02/06/requiring-https-for-certain-paths-in-django/</link>
		<comments>http://www.redrobotstudios.com/blog/2010/02/06/requiring-https-for-certain-paths-in-django/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 12:03:25 +0000</pubDate>
		<dc:creator>Scott Barnham</dc:creator>
				<category><![CDATA[Django]]></category>

		<guid isPermaLink="false">http://www.redrobotstudios.com/blog/?p=45</guid>
		<description><![CDATA[A while ago I wrote about Securing Django with SSL.  Here&#8217;s a small addition.
Some paths need https
If you&#8217;re using SSL it makes sense for certain parts of the site to require a secure connection.  For example, the admin section.
Previously I shared the secure_required decorator which forces requests to use https for specific views. [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I wrote about <a href="http://www.redrobotstudios.com/blog/2009/02/18/securing-django-with-ssl/">Securing Django with SSL</a>.  Here&#8217;s a small addition.</p>
<h3>Some paths need https</h3>
<p>If you&#8217;re using SSL it makes sense for certain parts of the site to require a secure connection.  For example, the admin section.</p>
<p>Previously I shared the <a href="http://www.redrobotstudios.com/blog/2009/02/18/securing-django-with-ssl/">secure_required</a> decorator which forces requests to use https for specific views.  This works ok, but if you know an entire section of the site under a given path (e.g. <code>/admin/</code>) should be secure, it&#8217;s hassle to have to add the decorator to each view.</p>
<p>You can require secure connections over https using webserver config or using Django itself.</p>
<h3>Requiring https using Nginx</h3>
<p>In your Nginx config file under the section for the unsecure http/port 80 server you can specify a location path and redirect all requests to it to https instead.</p>
<pre>server {
    listen 10.10.10.10:80;
    server_name example.com;
...
    location /admin {
        # force admin to use https
        rewrite (.*) https://example.com/$1 permanent;
    }
...
}
</pre>
<p>Apache and other web servers can have a similar configuration.</p>
<p>If you can configure it in the web server, that&#8217;s more efficient because the request can be redirected by the server, without having to contact your Django project.  However, it should be fairly rare for requests to be redirected like this so it&#8217;s not a big performance issue and sometimes it&#8217;s easier to handle things in Django.</p>
<h3>Requiring https using Django middleware</h3>
<p>In Django it&#8217;s easy to write <a href="http://docs.djangoproject.com/en/dev/topics/http/middleware/">custom middleware</a> which gets called before each request reaches a view.</p>
<p>Here&#8217;s a small piece of middleware which checks if the request is over http to a path we want to be secure and if so redirects to the same path but over https.</p>
<pre>from django.http import HttpResponsePermanentRedirect
from django.conf import settings

class SecureRequiredMiddleware(object):
    def __init__(self):
        self.paths = getattr(settings, 'SECURE_REQUIRED_PATHS')
        self.enabled = self.paths and getattr(settings, 'HTTPS_SUPPORT')

    def process_request(self, request):
        if self.enabled and not request.is_secure():
            for path in self.paths:
                if request.get_full_path().startswith(path):
                    request_url = request.build_absolute_uri(request.get_full_path())
                    secure_url = request_url.replace('http://', 'https://')
                    return HttpResponsePermanentRedirect(secure_url)
        return None</pre>
<p>In <code>settings.py</code></p>
<pre>MIDDLEWARE_CLASSES = (
...
    'myproject.middleware.SecureRequiredMiddleware',
)

HTTPS_SUPPORT = True
SECURE_REQUIRED_PATHS = (
    '/admin/',
    '/accounts/',
    '/management/',
)
</pre>
<p><code>SECURE_REQUIRED_PATHS</code> is a list or tuple of paths that should be secure.  Any request to a path which starts with one of these will be required to use https.</p>
<p><code>HTTPS_SUPPORT</code> is a custom setting to make it easier to use this on your dev server without SSL support.  Set it to <code>True</code> in the settings for the live server and <code>False</code> in the settings for the dev server.</p>
<p>So there we go, an easy way to require secure https requests for certain parts of your Django site.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redrobotstudios.com/blog/2010/02/06/requiring-https-for-certain-paths-in-django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find Nearby Developers on Djangogigs</title>
		<link>http://www.redrobotstudios.com/blog/2009/06/23/find-nearby-developers-on-djangogigs/</link>
		<comments>http://www.redrobotstudios.com/blog/2009/06/23/find-nearby-developers-on-djangogigs/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 08:46:47 +0000</pubDate>
		<dc:creator>Scott Barnham</dc:creator>
				<category><![CDATA[Djangogigs]]></category>

		<guid isPermaLink="false">http://www.redrobotstudios.com/blog2/?p=30</guid>
		<description><![CDATA[Djangogigs is a very successful job board we run for web developers who use the Django framework.  A few jobs and freelance gigs are added each week and there is a large directory of developers available&#160;for&#160;hire.
Finding&#160;Django&#160;Developers
As the number of developers increases, it becomes harder to find the person you are looking for.  A [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://djangogigs.com/">Djangogigs</a> is a very successful job board we run for web developers who use the <a href="http://www.djangoproject.com/">Django framework</a>.  A few jobs and freelance gigs are added each week and there is a large directory of developers available&nbsp;for&nbsp;hire.</p>
<h3>Finding&nbsp;Django&nbsp;Developers</h3>
<p>As the number of developers increases, it becomes harder to find the person you are looking for.  A while ago we added filtering by country, but for large countries such as the US, there are still way too many developer profiles to look through.  We now have nearly 700 <a href="http://djangogigs.com/developers/">Django developers</a> on the site and needed to find a&nbsp;better&nbsp;way.
</p>
<p>The solution we chose was <a href="http://en.wikipedia.org/wiki/Geocoding">geocoding</a> the location of each developer so that we can find developers who are close to a given location.  Ignoring the technical stuff, it&#8217;s very easy to use.  <strong>Just type in the name of your town or city and get back a list of developers who are nearby</strong>.</p>
<p>We&#8217;re confident this will make it much easier to find Django developers and may add other search options in future.  As always, we&#8217;re happy to hear <a href="http://getsatisfaction.com/redrobotstudios/products/redrobotstudios_djangogigs">your feedback</a>.
</p>
<h3>Follow us&nbsp;on&nbsp;Twitter</h3>
<p>We&#8217;ve also added a <a href="http://twitter.com/djangogigs">Djangogigs Twitter account</a> which you can follow to see the latest gigs as they&nbsp;are&nbsp;added.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redrobotstudios.com/blog/2009/06/23/find-nearby-developers-on-djangogigs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Securing Django with SSL</title>
		<link>http://www.redrobotstudios.com/blog/2009/02/18/securing-django-with-ssl/</link>
		<comments>http://www.redrobotstudios.com/blog/2009/02/18/securing-django-with-ssl/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 11:56:08 +0000</pubDate>
		<dc:creator>Scott Barnham</dc:creator>
				<category><![CDATA[Django]]></category>

		<guid isPermaLink="false">http://www.redrobotstudios.com/blog2/?p=42</guid>
		<description><![CDATA[When we built the centralized authentication system for Red Robot Studios we wanted all authentication and account resources to be available solely over&#160;https.

This article covers some tips and tricks we discovered while building the app, and how you can use Django to get fine-grained control as to which resources are available&#160;securely.

Why bother with&#160;security?
We all know [...]]]></description>
			<content:encoded><![CDATA[<p>When we built the centralized authentication system for <a href="http://www.redrobotstudios.com/">Red Robot Studios</a> we wanted all authentication and account resources to be available solely over&nbsp;https.
</p>
<p>This article covers some tips and tricks we discovered while building the app, and how you can use Django to get fine-grained control as to which resources are available&nbsp;securely.
</p>
<h3>Why bother with&nbsp;security?</h3>
<p>We all know that data sent over http is cleartext and can potentially be read on any network between the client and server.  But the risk feels pretty minimal and many sites don&#8217;t bother using <span class="caps">SSL</span> to encrypt sensitive traffic.  For online banking and ecommerce, you&#8217;d be crazy not to use it, but for other sites, why&nbsp;bother?</p>
<p>The chances of your http requests being snooped upon by an <span class="caps">ISP</span>, intermediate networks or your hosting company seem minimal.  But one potentially big risk is users accessing your website on an open wireless&nbsp;network.
</p>
<p>For example, perhaps your user has an unsecured wireless home or office network or maybe they use wireless networks in coffee shops and airports: It&#8217;s really easy in this situation for sensitive requests to be snooped&nbsp;upon.
</p>
<p>The data on your website may not be sensitive, but if you use Django&#8217;s admin or authentication frameworks, two important bits of information are passed as&nbsp;cleartext.
</p>
<p>When a user logs in, their username and password is posted in cleartext.  Assuming login is successful, each subsequent request includes a cookie containing the <code>sessionid</code>. The <code>sessionid</code> is just a random string, but if you know the <code>sessionid</code> of a user, it is trivial to hijack the session and have the same access to the website as that user does until they log&nbsp;out.</p>
<h3>Encrypting login&nbsp;sessions</h3>
<p>If you want to be sure user credentials and sessions cannot be compromised by eavesdroppers, you need to use <span class="caps">SSL</span> encryption.  Install an <span class="caps">SSL</span> certificate on the server so that traffic is encrypted end-to-end between client and&nbsp;server.
</p>
<p>You probably don&#8217;t want the whole site to be secure because it will be a lot slower and significantly increase the load on your servers.  Instead, you can be selective about which parts of the site should use https instead of http.  If you want user sessions to be secure, you should make sure that logging in and all parts of the site that require a logged-in user use&nbsp;https.</p>
<h3><span class="caps">SSL</span></h3>
<p>Standard <span class="caps">SSL</span> certificates are pretty cheap these days – under $20 per year.  We go some from <a href="http://www.rapidsslonline.com/">RapidSSLOnline</a>.  Each secure site needs its own <span class="caps">IP</span> address, so if you&#8217;re hosting multiple sites using virtual hosting, you&#8217;ll need to look in to getting some dedicated&nbsp;IPs.
</p>
<p>There are lots of guides to installing <span class="caps">SSL</span> certificates and configuring web servers such as Apache, Lighttpd and Nginx, so I won&#8217;t cover that&nbsp;here.
</p>
<h3>Making Django sessions&nbsp;secure</h3>
<p>Django uses cookies for its sessions.  When a cookie is set, you can specify that it be a secure cookie, meaning it is only ever passed over https and not in http requests.  We can tell Django to use secure cookies for sessions by adding a setting to <code>settings.py</code>
</p>
<pre><code>SESSION_COOKIE_SECURE = True
</code></pre>
<p>If you set Django to use secure cookies then try to log in over http you will get the&nbsp;error</p>
<blockquote><p><span class="dquo">&#8220;</span>Looks like your browser isn&#8217;t configured to accept cookies. Please enable cookies, reload this page, and try&nbsp;again.&#8221;
</p>
</blockquote>
<p>This happens because Django sets the cookie, but it&#8217;s a secure cookie, so when the page loads over http, Django can&#8217;t see the cookie and so assumes cookies are disabled in your&nbsp;browser.
</p>
<h3>Requiring https for&nbsp;admin</h3>
<p>To avoid this cookie warning and make sure you only ever pass your admin credentials over https, you can configure your web server so that any http requests are redirected to&nbsp;https.</p>
<p>For example, in Nginx it would look&nbsp;like:
</p>
<pre><code>server {
    server_name example.com;
    location /admin {
        # force admin to use https
        rewrite (.*) https://example.com/$1 permanent;
    }
...
}
</code></pre>
<p>In Apache, something&nbsp;like:
</p>
<pre><code>&lt;Location /admin&gt;
    RewriteRule (.*) https://example.com/$1 [L,R=301]
    ...
&lt;/Location&gt;
</code></pre>
<p>Of course, these bits of config should go in the http config, not the https config or you will cause infinite&nbsp;redirects!
</p>
<h3>Requiring https for certain&nbsp;views</h3>
<p>If all the logged-in parts of your site are in a certain path (e.g. /accounts/ and /members/) you can configure your web server in the same way to require https for these&nbsp;locations.
</p>
<p>If certain views require https (e.g. <code>/members/bert/</code> is public but <code>/members/bert/edit/</code> requires login), you may want to check <code>request.is_secure()</code> in those views.  A neat way to do it is with a decorator which can also redirect any http requests to&nbsp;https.</p>
<pre><code>from django.conf import settings
from django.http import HttpResponseRedirect

def secure_required(view_func):
    """Decorator makes sure URL is accessed over https."""
    def _wrapped_view_func(request, *args, **kwargs):
        if not request.is_secure():
            if getattr(settings, 'HTTPS_SUPPORT', True):
                request_url = request.build_absolute_uri(request.get_full_path())
                secure_url = request_url.replace('http://', 'https://')
                return HttpResponseRedirect(secure_url)
        return view_func(request, *args, **kwargs)
    return _wrapped_view_func
</code></pre>
<p>Then on your&nbsp;view:
</p>
<pre><code>@secure_required
@login_required
def edit_member(request, slug):
    ...
</code></pre>
<h3>Moving between http and https&nbsp;pages</h3>
<p>It&#8217;s normal to use full path URLs like <code>/accounts/login/</code> and <code>/blog/</code>.  Bear in mind that if you are accessing the site over https and follow one of these links, you will also access them over https.  If you want to be explicit, you need to specify the protocol and domain in the links, e.g. <strong>https</strong>://example.com/accounts/login/ and <strong>http</strong>://example.co/blog/&nbsp;.</p>
<p>For $20 and a bit of config, you can secure logged-in sessions on your site and protect yourself and your users from being compromised by eavesdroppers.  There are still plenty of sites where this is overkill, but you can see now how easy it is to secure your Django site with&nbsp;<span class="caps">SSL</span>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redrobotstudios.com/blog/2009/02/18/securing-django-with-ssl/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

