Ticket #16109: 16109.diff

File 16109.diff, 3.0 KB (added by Maura Chace, 13 years ago)
  • docs/ref/models/instances.txt

    diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt
    index 2053788..8809eaf 100644
    a b method that looked like this::  
    497497
    498498Similarly, if you had a URLconf entry that looked like::
    499499
    500     (r'/archive/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', archive_view)
     500    (r'/archive/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', archive_view)
    501501
    502502...you could reference this using ``permalink()`` as follows::
    503503
    Similarly, if you had a URLconf entry that looked like::  
    505505    def get_absolute_url(self):
    506506        return ('archive_view', (), {
    507507            'year': self.created.year,
    508             'month': self.created.month,
    509             'day': self.created.day})
     508            'month': self.created.strftime('%m'),
     509            'day': self.created.strftime('%d')})
    510510
    511511Notice that we specify an empty sequence for the second parameter in this case,
    512512because we only want to pass keyword parameters, not positional ones.
  • docs/topics/http/urls.txt

    diff --git a/docs/topics/http/urls.txt b/docs/topics/http/urls.txt
    index 4bb3b78..3f68cdb 100644
    a b Example requests:  
    105105    * ``/articles/2003`` would not match any of these patterns, because each
    106106      pattern requires that the URL end with a slash.
    107107
    108     * ``/articles/2003/03/3/`` would match the final pattern. Django would call
    109       the function ``news.views.article_detail(request, '2003', '03', '3')``.
     108    * ``/articles/2003/03/03/`` would match the final pattern. Django would call
     109      the function ``news.views.article_detail(request, '2003', '03', '03')``.
    110110
    111111.. _Dive Into Python's explanation: http://diveintopython.org/regular_expressions/street_addresses.html#re.matching.2.3
    112112
    Here's the above example URLconf, rewritten to use named groups::  
    129129        (r'^articles/2003/$', 'news.views.special_case_2003'),
    130130        (r'^articles/(?P<year>\d{4})/$', 'news.views.year_archive'),
    131131        (r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'news.views.month_archive'),
    132         (r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d+)/$', 'news.views.article_detail'),
     132        (r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', 'news.views.article_detail'),
    133133    )
    134134
    135135This accomplishes exactly the same thing as the previous example, with one
    arguments rather than positional arguments. For example:  
    140140      ``news.views.month_archive(request, year='2005', month='03')``, instead
    141141      of ``news.views.month_archive(request, '2005', '03')``.
    142142
    143     * A request to ``/articles/2003/03/3/`` would call the function
    144       ``news.views.article_detail(request, year='2003', month='03', day='3')``.
     143    * A request to ``/articles/2003/03/03/`` would call the function
     144      ``news.views.article_detail(request, year='2003', month='03', day='03')``.
    145145
    146146In practice, this means your URLconfs are slightly more explicit and less prone
    147147to argument-order bugs -- and you can reorder the arguments in your views'
Back to Top