From 66ec9ee441618894c1ccebdcdd5eb4d7fbf4a6d3 Mon Sep 17 00:00:00 2001 From: chriscauley Date: Mon, 14 Apr 2014 14:12:44 -0400 Subject: Fixed #22378 -- Updated \d to [0-9]+ in urlpatterns of docs and tests. Thanks tomwys for the suggestion. --- docs/intro/overview.txt | 6 +++--- docs/intro/tutorial03.txt | 16 ++++++++-------- docs/intro/tutorial04.txt | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'docs/intro') diff --git a/docs/intro/overview.txt b/docs/intro/overview.txt index 42d80f66cd..685666f8cb 100644 --- a/docs/intro/overview.txt +++ b/docs/intro/overview.txt @@ -187,9 +187,9 @@ example above:: from django.conf.urls import url urlpatterns = [ - url(r'^articles/(\d{4})/$', 'news.views.year_archive'), - url(r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'), - url(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'), + url(r'^articles/([0-9]{4})/$', 'news.views.year_archive'), + url(r'^articles/([0-9]{4})/([0-9]{2})/$', 'news.views.month_archive'), + url(r'^articles/([0-9]{4})/([0-9]{2})/([0-9]+)/$', 'news.views.article_detail'), ] The code above maps URLs, as simple `regular expressions`_, to the location of diff --git a/docs/intro/tutorial03.txt b/docs/intro/tutorial03.txt index 3d4f65a720..1d25a58711 100644 --- a/docs/intro/tutorial03.txt +++ b/docs/intro/tutorial03.txt @@ -215,11 +215,11 @@ Wire these new views into the ``polls.urls`` module by adding the following # ex: /polls/ url(r'^$', views.index, name='index'), # ex: /polls/5/ - url(r'^(?P\d+)/$', views.detail, name='detail'), + url(r'^(?P[0-9]+)/$', views.detail, name='detail'), # ex: /polls/5/results/ - url(r'^(?P\d+)/results/$', views.results, name='results'), + url(r'^(?P[0-9]+)/results/$', views.results, name='results'), # ex: /polls/5/vote/ - url(r'^(?P\d+)/vote/$', views.vote, name='vote'), + url(r'^(?P[0-9]+)/vote/$', views.vote, name='vote'), ] Take a look in your browser, at "/polls/34/". It'll run the ``detail()`` @@ -251,15 +251,15 @@ Here's what happens if a user goes to "/polls/34/" in this system: * Then, Django will strip off the matching text (``"polls/"``) and send the remaining text -- ``"34/"`` -- to the 'polls.urls' URLconf for - further processing which matches ``r'^(?P\d+)/$'`` resulting in a + further processing which matches ``r'^(?P[0-9]+)/$'`` resulting in a call to the ``detail()`` view like so:: detail(request=, question_id='34') -The ``question_id='34'`` part comes from ``(?P\d+)``. Using parentheses +The ``question_id='34'`` part comes from ``(?P[0-9]+)``. Using parentheses around a pattern "captures" the text matched by that pattern and sends it as an argument to the view function; ``?P`` defines the name that will -be used to identify the matched pattern; and ``\d+`` is a regular expression to +be used to identify the matched pattern; and ``[0-9]+`` is a regular expression to match a sequence of digits (i.e., a number). Because the URL patterns are regular expressions, there really is no limit on @@ -554,7 +554,7 @@ defined below:: ... # the 'name' value as called by the {% url %} template tag - url(r'^(?P\d+)/$', views.detail, name='detail'), + url(r'^(?P[0-9]+)/$', views.detail, name='detail'), ... If you want to change the URL of the polls detail view to something else, @@ -563,7 +563,7 @@ template (or templates) you would change it in ``polls/urls.py``:: ... # added the word 'specifics' - url(r'^specifics/(?P\d+)/$', views.detail, name='detail'), + url(r'^specifics/(?P[0-9]+)/$', views.detail, name='detail'), ... Namespacing URL names diff --git a/docs/intro/tutorial04.txt b/docs/intro/tutorial04.txt index 63d12d1a68..5b46dc0bb8 100644 --- a/docs/intro/tutorial04.txt +++ b/docs/intro/tutorial04.txt @@ -61,7 +61,7 @@ created a URLconf for the polls application that includes this line: .. snippet:: :filename: polls/urls.py - url(r'^(?P\d+)/vote/$', views.vote, name='vote'), + url(r'^(?P[0-9]+)/vote/$', views.vote, name='vote'), We also created a dummy implementation of the ``vote()`` function. Let's create a real version. Add the following to ``polls/views.py``: @@ -228,9 +228,9 @@ First, open the ``polls/urls.py`` URLconf and change it like so: urlpatterns = [ url(r'^$', views.IndexView.as_view(), name='index'), - url(r'^(?P\d+)/$', views.DetailView.as_view(), name='detail'), - url(r'^(?P\d+)/results/$', views.ResultsView.as_view(), name='results'), - url(r'^(?P\d+)/vote/$', views.vote, name='vote'), + url(r'^(?P[0-9]+)/$', views.DetailView.as_view(), name='detail'), + url(r'^(?P[0-9]+)/results/$', views.ResultsView.as_view(), name='results'), + url(r'^(?P[0-9]+)/vote/$', views.vote, name='vote'), ] Amend views -- cgit v1.3