Commits

Anonymous committed 6668932

[1.3.X] Fixed #17171 -- Updated tutorial urls.py code snippets to match startproject template and recommended practice. (No 'import *', use 'urls()' function.). Thanks haimunt for report.

Parts of this are a backport of r17073 from trunk.

Comments (0)

Files changed (3)

docs/intro/tutorial02.txt

 
       .. parsed-literal::
 
-          from django.conf.urls.defaults import *
+          from django.conf.urls.defaults import patterns, include, url
 
           # Uncomment the next two lines to enable the admin:
           **from django.contrib import admin**
           **admin.autodiscover()**
 
           urlpatterns = patterns('',
-              # Example:
-              # (r'^mysite/', include('mysite.foo.urls')),
+              # Examples:
+              # url(r'^$', 'mysite.views.home', name='home'),
+              # url(r'^mysite/', include('mysite.foo.urls')),
 
-              # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
-              # to INSTALLED_APPS to enable admin documentation:
-              # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
+              # Uncomment the admin/doc line below to enable admin documentation:
+              # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
 
               # Uncomment the next line to enable the admin:
-              **(r'^admin/', include(admin.site.urls)),**
+              **url(r'^admin/', include(admin.site.urls)),**
           )
 
       (The bold lines are the ones that needed to be uncommented.)

docs/intro/tutorial03.txt

 
 Time for an example. Edit ``mysite/urls.py`` so it looks like this::
 
-    from django.conf.urls.defaults import *
+    from django.conf.urls.defaults import patterns, include, url
 
     from django.contrib import admin
     admin.autodiscover()
 
     urlpatterns = patterns('',
-        (r'^polls/$', 'polls.views.index'),
-        (r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),
-        (r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'),
-        (r'^polls/(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),
-        (r'^admin/', include(admin.site.urls)),
+        url(r'^polls/$', 'polls.views.index'),
+        url(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),
+        url(r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'),
+        url(r'^polls/(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),
+        url(r'^admin/', include(admin.site.urls)),
     )
 
 This is worth a review. When somebody requests a page from your Web site -- say,
 -- unless you have a sick sense of humor, in which case you can do something
 like this::
 
-    (r'^polls/latest\.php$', 'polls.views.index'),
+    url(r'^polls/latest\.php$', 'polls.views.index'),
 
 But, don't do that. It's silly.
 
 the URLconf, you may notice there's a fair bit of redundancy in it::
 
     urlpatterns = patterns('',
-        (r'^polls/$', 'polls.views.index'),
-        (r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),
-        (r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'),
-        (r'^polls/(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),
+        url(r'^polls/$', 'polls.views.index'),
+        url(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),
+        url(r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'),
+        url(r'^polls/(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),
     )
 
 Namely, ``polls.views`` is in every callback.
 first argument to :func:`~django.conf.urls.defaults.patterns`, like so::
 
     urlpatterns = patterns('polls.views',
-        (r'^polls/$', 'index'),
-        (r'^polls/(?P<poll_id>\d+)/$', 'detail'),
-        (r'^polls/(?P<poll_id>\d+)/results/$', 'results'),
-        (r'^polls/(?P<poll_id>\d+)/vote/$', 'vote'),
+        url(r'^polls/$', 'index'),
+        url(r'^polls/(?P<poll_id>\d+)/$', 'detail'),
+        url(r'^polls/(?P<poll_id>\d+)/results/$', 'results'),
+        url(r'^polls/(?P<poll_id>\d+)/vote/$', 'vote'),
     )
 
 This is functionally identical to the previous formatting. It's just a bit
 :func:`~django.conf.urls.defaults.patterns`. Your full ``mysite/urls.py`` might
 now look like this::
 
-    from django.conf.urls.defaults import *
+    from django.conf.urls.defaults import patterns, include, url
 
     from django.contrib import admin
     admin.autodiscover()
     
     urlpatterns = patterns('polls.views',
-        (r'^polls/$', 'index'),
-        (r'^polls/(?P<poll_id>\d+)/$', 'detail'),
-        (r'^polls/(?P<poll_id>\d+)/results/$', 'results'),
-        (r'^polls/(?P<poll_id>\d+)/vote/$', 'vote'),
+        url(r'^polls/$', 'index'),
+        url(r'^polls/(?P<poll_id>\d+)/$', 'detail'),
+        url(r'^polls/(?P<poll_id>\d+)/results/$', 'results'),
+        url(r'^polls/(?P<poll_id>\d+)/vote/$', 'vote'),
     )
     
     urlpatterns += patterns('',
-        (r'^admin/', include(admin.site.urls)),
+        url(r'^admin/', include(admin.site.urls)),
     )
 
 Decoupling the URLconfs
     admin.autodiscover()
     
     urlpatterns = patterns('',
-        (r'^polls/', include('polls.urls')),
-        (r'^admin/', include(admin.site.urls)),
+        url(r'^polls/', include('polls.urls')),
+        url(r'^admin/', include(admin.site.urls)),
     )
 
 :func:`~django.conf.urls.defaults.include` simply references another URLconf.
 lines registering the admin site. Your ``polls/urls.py`` file should now look like
 this::
 
-    from django.conf.urls.defaults import *
+    from django.conf.urls.defaults import patterns, include, url
 
     urlpatterns = patterns('polls.views',
-        (r'^$', 'index'),
-        (r'^(?P<poll_id>\d+)/$', 'detail'),
-        (r'^(?P<poll_id>\d+)/results/$', 'results'),
-        (r'^(?P<poll_id>\d+)/vote/$', 'vote'),
+        url(r'^$', 'index'),
+        url(r'^(?P<poll_id>\d+)/$', 'detail'),
+        url(r'^(?P<poll_id>\d+)/results/$', 'results'),
+        url(r'^(?P<poll_id>\d+)/vote/$', 'vote'),
     )
 
 The idea behind :func:`~django.conf.urls.defaults.include` and URLconf

docs/intro/tutorial04.txt

 First, open the ``polls/urls.py`` URLconf. It looks like this, according to the
 tutorial so far::
 
-    from django.conf.urls.defaults import *
+    from django.conf.urls.defaults import patterns, include, url
 
     urlpatterns = patterns('polls.views',
-        (r'^$', 'index'),
-        (r'^(?P<poll_id>\d+)/$', 'detail'),
-        (r'^(?P<poll_id>\d+)/results/$', 'results'),
-        (r'^(?P<poll_id>\d+)/vote/$', 'vote'),
+        url(r'^$', 'index'),
+        url(r'^(?P<poll_id>\d+)/$', 'detail'),
+        url(r'^(?P<poll_id>\d+)/results/$', 'results'),
+        url(r'^(?P<poll_id>\d+)/vote/$', 'vote'),
     )
 
 Change it like so::
     from polls.models import Poll
 
     urlpatterns = patterns('',
-        (r'^$',
+        url(r'^$',
             ListView.as_view(
                 queryset=Poll.objects.order_by('-pub_date')[:5],
                 context_object_name='latest_poll_list',
                 template_name='polls/index.html')),
-        (r'^(?P<pk>\d+)/$',
+        url(r'^(?P<pk>\d+)/$',
             DetailView.as_view(
                 model=Poll,
                 template_name='polls/detail.html')),
                 model=Poll,
                 template_name='polls/results.html'),
             name='poll_results'),
-        (r'^(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),
+        url(r'^(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),
     )
 
 We're using two generic views here: