title: Zero fill numbers in Djangos URLconf
body: <p>In the <a href="http://docs.djangoproject.com/en/1.3/topics/http/urls/#example" rel="nofollow">documentation of Django</a> is an example pattern for an URL of an article:</p>
  
  <pre><code>(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'),
  </code></pre>
  
  <p>So, only <code>2011/05/23/</code> will match, but not <code>2011/5/23/</code></p>
  
  <p>In another part of the docs, where the <a href="http://docs.djangoproject.com/en/1.3/ref/models/instances/#django.db.models.permalink" rel="nofollow">permalinks decorator</a> is  explained, the pattern is</p>
  
  <pre><code>(r'/archive/(?P&lt;year&gt;\d{4})/(?P&lt;month&gt;\d{1,2})/(?P&lt;day&gt;\d{1,2})/$', archive_view)
  </code></pre>
  
  <p>And the code for creating a permalink</p>
  
  <pre><code>@models.permalink
  def get_absolute_url(self):
      return ('archive_view', (), {
          'year': self.created.year,
          'month': self.created.month,
          'day': self.created.day})
  </code></pre>
  
  <p>In particular, month has changed from <code>\d{2}</code> to <code>\d{1,2}</code>, so <code>2011/05/23/</code> and <code>2011/5/23/</code> will now both match; the <code>get_absolute_url</code> method will create the second link, without leading zero.</p>
  
  <p>To create a permalink for the first regex (<code>\d{2}</code>), I could write <code>str(self.created.month).zfill(2)</code> in the method, but this seems a bit cumbersome and too redundant (if I change the URLconf, I will need to change the <code>get_absolute_url</code> method, too) to me.</p>
  
  <p>Additionally, we have now multiple urls which all display the same content (<code>2011/05/03/</code>, <code>2011/5/03/</code>, <code>2011/05/3/</code>, etc.), could that be a problem, e.g. for search engines? At least it can result in inconsistent urls.</p>
  
  <p>Is there a (simple) way to redirect all urls to the zero filled ones (<code>2011/5/3/</code> › <code>2011/05/03/</code>) and also automatically always build them zerofilled, so I don't need to mess around in methods like <code>get_absolute_url</code> with str() and zfill and can just pass the number?</p>