Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refs #17171 -- Updated tutorial sections 3 and 4 to follow the startp…

…roject template and consistently use url() function in URLconf. Thanks haimunt for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17073 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7f658a5429f1b8eb72157535ecdc05a136dc2be4 1 parent 5f64af9
Carl Meyer authored November 06, 2011
43  docs/intro/tutorial03.txt
@@ -84,10 +84,10 @@ Time for an example. Edit ``mysite/urls.py`` so it looks like this::
84 84
     admin.autodiscover()
85 85
 
86 86
     urlpatterns = patterns('',
87  
-        (r'^polls/$', 'polls.views.index'),
88  
-        (r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),
89  
-        (r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'),
90  
-        (r'^polls/(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),
  87
+        url(r'^polls/$', 'polls.views.index'),
  88
+        url(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),
  89
+        url(r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'),
  90
+        url(r'^polls/(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),
91 91
         url(r'^admin/', include(admin.site.urls)),
92 92
     )
93 93
 
@@ -434,10 +434,10 @@ Take some time to play around with the views and template system. As you edit
434 434
 the URLconf, you may notice there's a fair bit of redundancy in it::
435 435
 
436 436
     urlpatterns = patterns('',
437  
-        (r'^polls/$', 'polls.views.index'),
438  
-        (r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),
439  
-        (r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'),
440  
-        (r'^polls/(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),
  437
+        url(r'^polls/$', 'polls.views.index'),
  438
+        url(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),
  439
+        url(r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'),
  440
+        url(r'^polls/(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),
441 441
     )
442 442
 
443 443
 Namely, ``polls.views`` is in every callback.
@@ -447,10 +447,10 @@ common prefixes. You can factor out the common prefixes and add them as the
447 447
 first argument to :func:`~django.conf.urls.patterns`, like so::
448 448
 
449 449
     urlpatterns = patterns('polls.views',
450  
-        (r'^polls/$', 'index'),
451  
-        (r'^polls/(?P<poll_id>\d+)/$', 'detail'),
452  
-        (r'^polls/(?P<poll_id>\d+)/results/$', 'results'),
453  
-        (r'^polls/(?P<poll_id>\d+)/vote/$', 'vote'),
  450
+        url(r'^polls/$', 'index'),
  451
+        url(r'^polls/(?P<poll_id>\d+)/$', 'detail'),
  452
+        url(r'^polls/(?P<poll_id>\d+)/results/$', 'results'),
  453
+        url(r'^polls/(?P<poll_id>\d+)/vote/$', 'vote'),
454 454
     )
455 455
 
456 456
 This is functionally identical to the previous formatting. It's just a bit
@@ -467,10 +467,10 @@ now look like this::
467 467
     admin.autodiscover()
468 468
 
469 469
     urlpatterns = patterns('polls.views',
470  
-        (r'^polls/$', 'index'),
471  
-        (r'^polls/(?P<poll_id>\d+)/$', 'detail'),
472  
-        (r'^polls/(?P<poll_id>\d+)/results/$', 'results'),
473  
-        (r'^polls/(?P<poll_id>\d+)/vote/$', 'vote'),
  470
+        url(r'^polls/$', 'index'),
  471
+        url(r'^polls/(?P<poll_id>\d+)/$', 'detail'),
  472
+        url(r'^polls/(?P<poll_id>\d+)/results/$', 'results'),
  473
+        url(r'^polls/(?P<poll_id>\d+)/vote/$', 'vote'),
474 474
     )
475 475
 
476 476
     urlpatterns += patterns('',
@@ -497,14 +497,13 @@ Copy the file ``mysite/urls.py`` to ``polls/urls.py``. Then, change
497 497
 ``mysite/urls.py`` to remove the poll-specific URLs and insert an
498 498
 :func:`~django.conf.urls.include`, leaving you with::
499 499
 
500  
-    # This also imports the include function
501 500
     from django.conf.urls import patterns, include, url
502 501
 
503 502
     from django.contrib import admin
504 503
     admin.autodiscover()
505 504
 
506 505
     urlpatterns = patterns('',
507  
-        (r'^polls/', include('polls.urls')),
  506
+        url(r'^polls/', include('polls.urls')),
508 507
         url(r'^admin/', include(admin.site.urls)),
509 508
     )
510 509
 
@@ -531,10 +530,10 @@ this::
531 530
     from django.conf.urls import patterns, include, url
532 531
 
533 532
     urlpatterns = patterns('polls.views',
534  
-        (r'^$', 'index'),
535  
-        (r'^(?P<poll_id>\d+)/$', 'detail'),
536  
-        (r'^(?P<poll_id>\d+)/results/$', 'results'),
537  
-        (r'^(?P<poll_id>\d+)/vote/$', 'vote'),
  533
+        url(r'^$', 'index'),
  534
+        url(r'^(?P<poll_id>\d+)/$', 'detail'),
  535
+        url(r'^(?P<poll_id>\d+)/results/$', 'results'),
  536
+        url(r'^(?P<poll_id>\d+)/vote/$', 'vote'),
538 537
     )
539 538
 
540 539
 The idea behind :func:`~django.conf.urls.include` and URLconf
14  docs/intro/tutorial04.txt
@@ -221,10 +221,10 @@ tutorial so far::
221 221
     from django.conf.urls import patterns, include, url
222 222
 
223 223
     urlpatterns = patterns('polls.views',
224  
-        (r'^$', 'index'),
225  
-        (r'^(?P<poll_id>\d+)/$', 'detail'),
226  
-        (r'^(?P<poll_id>\d+)/results/$', 'results'),
227  
-        (r'^(?P<poll_id>\d+)/vote/$', 'vote'),
  224
+        url(r'^$', 'index'),
  225
+        url(r'^(?P<poll_id>\d+)/$', 'detail'),
  226
+        url(r'^(?P<poll_id>\d+)/results/$', 'results'),
  227
+        url(r'^(?P<poll_id>\d+)/vote/$', 'vote'),
228 228
     )
229 229
 
230 230
 Change it like so::
@@ -234,12 +234,12 @@ Change it like so::
234 234
     from polls.models import Poll
235 235
 
236 236
     urlpatterns = patterns('',
237  
-        (r'^$',
  237
+        url(r'^$',
238 238
             ListView.as_view(
239 239
                 queryset=Poll.objects.order_by('-pub_date')[:5],
240 240
                 context_object_name='latest_poll_list',
241 241
                 template_name='polls/index.html')),
242  
-        (r'^(?P<pk>\d+)/$',
  242
+        url(r'^(?P<pk>\d+)/$',
243 243
             DetailView.as_view(
244 244
                 model=Poll,
245 245
                 template_name='polls/detail.html')),
@@ -248,7 +248,7 @@ Change it like so::
248 248
                 model=Poll,
249 249
                 template_name='polls/results.html'),
250 250
             name='poll_results'),
251  
-        (r'^(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),
  251
+        url(r'^(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),
252 252
     )
253 253
 
254 254
 We're using two generic views here:

0 notes on commit 7f658a5

Please sign in to comment.
Something went wrong with that request. Please try again.