Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #15614 -- Fixed potentially confusing URLconf examples in docs/…

…ref/generic-views.txt by adding explicit import statement and using function passing instead of strings in the URLpattern

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15822 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b1f67e73174e09476bbbd8ddff547c324940313c 1 parent 6eb1c58
Adrian Holovaty authored March 15, 2011

Showing 1 changed file with 21 additions and 11 deletions. Show diff stats Hide diff stats

  1. 32  docs/ref/generic-views.txt
32  docs/ref/generic-views.txt
@@ -62,9 +62,11 @@ which is a dictionary of the parameters captured in the URL.
62 62
 
63 63
 Given the following URL patterns::
64 64
 
65  
-    urlpatterns = patterns('django.views.generic.simple',
66  
-        (r'^foo/$',             'direct_to_template', {'template': 'foo_index.html'}),
67  
-        (r'^foo/(?P<id>\d+)/$', 'direct_to_template', {'template': 'foo_detail.html'}),
  65
+    from django.views.generic.simple import direct_to_template
  66
+
  67
+    urlpatterns = patterns('',
  68
+        (r'^foo/$',             direct_to_template, {'template': 'foo_index.html'}),
  69
+        (r'^foo/(?P<id>\d+)/$', direct_to_template, {'template': 'foo_detail.html'}),
68 70
     )
69 71
 
70 72
 ... a request to ``/foo/`` would render the template ``foo_index.html``, and a
@@ -111,29 +113,37 @@ If the given URL is ``None``, Django will return an ``HttpResponseGone`` (410).
111 113
 This example issues a permanent redirect (HTTP status code 301) from
112 114
 ``/foo/<id>/`` to ``/bar/<id>/``::
113 115
 
114  
-    urlpatterns = patterns('django.views.generic.simple',
115  
-        ('^foo/(?P<id>\d+)/$', 'redirect_to', {'url': '/bar/%(id)s/'}),
  116
+    from django.views.generic.simple import redirect_to
  117
+
  118
+    urlpatterns = patterns('',
  119
+        ('^foo/(?P<id>\d+)/$', redirect_to, {'url': '/bar/%(id)s/'}),
116 120
     )
117 121
 
118 122
 This example issues a non-permanent redirect (HTTP status code 302) from
119 123
 ``/foo/<id>/`` to ``/bar/<id>/``::
120 124
 
121  
-    urlpatterns = patterns('django.views.generic.simple',
122  
-        ('^foo/(?P<id>\d+)/$', 'redirect_to', {'url': '/bar/%(id)s/', 'permanent': False}),
  125
+    from django.views.generic.simple import redirect_to
  126
+
  127
+    urlpatterns = patterns('',
  128
+        ('^foo/(?P<id>\d+)/$', redirect_to, {'url': '/bar/%(id)s/', 'permanent': False}),
123 129
     )
124 130
 
125 131
 This example returns a 410 HTTP error for requests to ``/bar/``::
126 132
 
127  
-    urlpatterns = patterns('django.views.generic.simple',
128  
-        ('^bar/$', 'redirect_to', {'url': None}),
  133
+    from django.views.generic.simple import redirect_to
  134
+
  135
+    urlpatterns = patterns('',
  136
+        ('^bar/$', redirect_to, {'url': None}),
129 137
     )
130 138
 
131 139
 This example shows how ``"%"`` characters must be written in the URL in order
132 140
 to avoid confusion with Python's string formatting markers. If the redirect
133 141
 string is written as ``"%7Ejacob/"`` (with only a single ``%``), an exception would be raised::
134 142
 
135  
-    urlpatterns = patterns('django.views.generic.simple',
136  
-        ('^bar/$', 'redirect_to', {'url': '%%7Ejacob.'}),
  143
+    from django.views.generic.simple import redirect_to
  144
+
  145
+    urlpatterns = patterns('',
  146
+        ('^bar/$', redirect_to, {'url': '%%7Ejacob.'}),
137 147
     )
138 148
 
139 149
 Date-based generic views

0 notes on commit b1f67e7

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