From b1f67e73174e09476bbbd8ddff547c324940313c Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Tue, 15 Mar 2011 17:07:16 +0000 Subject: [PATCH] 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 --- docs/ref/generic-views.txt | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/docs/ref/generic-views.txt b/docs/ref/generic-views.txt index fe3ff808c2..0a589f0bd4 100644 --- a/docs/ref/generic-views.txt +++ b/docs/ref/generic-views.txt @@ -62,9 +62,11 @@ which is a dictionary of the parameters captured in the URL. Given the following URL patterns:: - urlpatterns = patterns('django.views.generic.simple', - (r'^foo/$', 'direct_to_template', {'template': 'foo_index.html'}), - (r'^foo/(?P\d+)/$', 'direct_to_template', {'template': 'foo_detail.html'}), + from django.views.generic.simple import direct_to_template + + urlpatterns = patterns('', + (r'^foo/$', direct_to_template, {'template': 'foo_index.html'}), + (r'^foo/(?P\d+)/$', direct_to_template, {'template': 'foo_detail.html'}), ) ... 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). This example issues a permanent redirect (HTTP status code 301) from ``/foo//`` to ``/bar//``:: - urlpatterns = patterns('django.views.generic.simple', - ('^foo/(?P\d+)/$', 'redirect_to', {'url': '/bar/%(id)s/'}), + from django.views.generic.simple import redirect_to + + urlpatterns = patterns('', + ('^foo/(?P\d+)/$', redirect_to, {'url': '/bar/%(id)s/'}), ) This example issues a non-permanent redirect (HTTP status code 302) from ``/foo//`` to ``/bar//``:: - urlpatterns = patterns('django.views.generic.simple', - ('^foo/(?P\d+)/$', 'redirect_to', {'url': '/bar/%(id)s/', 'permanent': False}), + from django.views.generic.simple import redirect_to + + urlpatterns = patterns('', + ('^foo/(?P\d+)/$', redirect_to, {'url': '/bar/%(id)s/', 'permanent': False}), ) This example returns a 410 HTTP error for requests to ``/bar/``:: - urlpatterns = patterns('django.views.generic.simple', - ('^bar/$', 'redirect_to', {'url': None}), + from django.views.generic.simple import redirect_to + + urlpatterns = patterns('', + ('^bar/$', redirect_to, {'url': None}), ) This example shows how ``"%"`` characters must be written in the URL in order to avoid confusion with Python's string formatting markers. If the redirect string is written as ``"%7Ejacob/"`` (with only a single ``%``), an exception would be raised:: - urlpatterns = patterns('django.views.generic.simple', - ('^bar/$', 'redirect_to', {'url': '%%7Ejacob.'}), + from django.views.generic.simple import redirect_to + + urlpatterns = patterns('', + ('^bar/$', redirect_to, {'url': '%%7Ejacob.'}), ) Date-based generic views