Skip to content

Commit

Permalink
[1.3.X] Fixed #16109: Corrected an inconsistency in URLconf examples …
Browse files Browse the repository at this point in the history
…for matching a numeric month. Backport of [16811] from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.3.X@16812 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
ubernostrum committed Sep 11, 2011
1 parent f242c02 commit 16787c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions docs/ref/models/instances.txt
Expand Up @@ -470,16 +470,16 @@ the URL. For example, if your URLconf contained a line such as::


Similarly, if you had a URLconf entry that looked like:: Similarly, if you had a URLconf entry that looked like::


(r'/archive/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', archive_view) (r'/archive/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', archive_view)


...you could reference this using ``permalink()`` as follows:: ...you could reference this using ``permalink()`` as follows::


@models.permalink @models.permalink
def get_absolute_url(self): def get_absolute_url(self):
return ('archive_view', (), { return ('archive_view', (), {
'year': self.created.year, 'year': self.created.year,
'month': self.created.month, 'month': self.created.strftime('%m'),
'day': self.created.day}) 'day': self.created.strftime('%d')})


Notice that we specify an empty sequence for the second parameter in this case, Notice that we specify an empty sequence for the second parameter in this case,
because we only want to pass keyword parameters, not positional ones. because we only want to pass keyword parameters, not positional ones.
Expand Down
10 changes: 5 additions & 5 deletions docs/topics/http/urls.txt
Expand Up @@ -103,8 +103,8 @@ Example requests:
* ``/articles/2003`` would not match any of these patterns, because each * ``/articles/2003`` would not match any of these patterns, because each
pattern requires that the URL end with a slash. pattern requires that the URL end with a slash.


* ``/articles/2003/03/3/`` would match the final pattern. Django would call * ``/articles/2003/03/03/`` would match the final pattern. Django would call
the function ``news.views.article_detail(request, '2003', '03', '3')``. the function ``news.views.article_detail(request, '2003', '03', '03')``.


.. _Dive Into Python's explanation: http://diveintopython.org/regular_expressions/street_addresses.html#re.matching.2.3 .. _Dive Into Python's explanation: http://diveintopython.org/regular_expressions/street_addresses.html#re.matching.2.3


Expand All @@ -127,7 +127,7 @@ Here's the above example URLconf, rewritten to use named groups::
(r'^articles/2003/$', 'news.views.special_case_2003'), (r'^articles/2003/$', 'news.views.special_case_2003'),
(r'^articles/(?P<year>\d{4})/$', 'news.views.year_archive'), (r'^articles/(?P<year>\d{4})/$', 'news.views.year_archive'),
(r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'news.views.month_archive'), (r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'news.views.month_archive'),
(r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d+)/$', 'news.views.article_detail'), (r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', 'news.views.article_detail'),
) )


This accomplishes exactly the same thing as the previous example, with one This accomplishes exactly the same thing as the previous example, with one
Expand All @@ -138,8 +138,8 @@ arguments rather than positional arguments. For example:
``news.views.month_archive(request, year='2005', month='03')``, instead ``news.views.month_archive(request, year='2005', month='03')``, instead
of ``news.views.month_archive(request, '2005', '03')``. of ``news.views.month_archive(request, '2005', '03')``.


* A request to ``/articles/2003/03/3/`` would call the function * A request to ``/articles/2003/03/03/`` would call the function
``news.views.article_detail(request, year='2003', month='03', day='3')``. ``news.views.article_detail(request, year='2003', month='03', day='03')``.


In practice, this means your URLconfs are slightly more explicit and less prone In practice, this means your URLconfs are slightly more explicit and less prone
to argument-order bugs -- and you can reorder the arguments in your views' to argument-order bugs -- and you can reorder the arguments in your views'
Expand Down

0 comments on commit 16787c6

Please sign in to comment.