Kaydet (Commit) b1f67e73 authored tarafından Adrian Holovaty's avatar Adrian Holovaty

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

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
üst 6eb1c584
...@@ -62,9 +62,11 @@ which is a dictionary of the parameters captured in the URL. ...@@ -62,9 +62,11 @@ which is a dictionary of the parameters captured in the URL.
Given the following URL patterns:: Given the following URL patterns::
urlpatterns = patterns('django.views.generic.simple', from django.views.generic.simple import direct_to_template
(r'^foo/$', 'direct_to_template', {'template': 'foo_index.html'}),
(r'^foo/(?P<id>\d+)/$', 'direct_to_template', {'template': 'foo_detail.html'}), urlpatterns = patterns('',
(r'^foo/$', direct_to_template, {'template': 'foo_index.html'}),
(r'^foo/(?P<id>\d+)/$', direct_to_template, {'template': 'foo_detail.html'}),
) )
... a request to ``/foo/`` would render the template ``foo_index.html``, and a ... 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,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 This example issues a permanent redirect (HTTP status code 301) from
``/foo/<id>/`` to ``/bar/<id>/``:: ``/foo/<id>/`` to ``/bar/<id>/``::
urlpatterns = patterns('django.views.generic.simple', from django.views.generic.simple import redirect_to
('^foo/(?P<id>\d+)/$', 'redirect_to', {'url': '/bar/%(id)s/'}),
urlpatterns = patterns('',
('^foo/(?P<id>\d+)/$', redirect_to, {'url': '/bar/%(id)s/'}),
) )
This example issues a non-permanent redirect (HTTP status code 302) from This example issues a non-permanent redirect (HTTP status code 302) from
``/foo/<id>/`` to ``/bar/<id>/``:: ``/foo/<id>/`` to ``/bar/<id>/``::
urlpatterns = patterns('django.views.generic.simple', from django.views.generic.simple import redirect_to
('^foo/(?P<id>\d+)/$', 'redirect_to', {'url': '/bar/%(id)s/', 'permanent': False}),
urlpatterns = patterns('',
('^foo/(?P<id>\d+)/$', redirect_to, {'url': '/bar/%(id)s/', 'permanent': False}),
) )
This example returns a 410 HTTP error for requests to ``/bar/``:: This example returns a 410 HTTP error for requests to ``/bar/``::
urlpatterns = patterns('django.views.generic.simple', from django.views.generic.simple import redirect_to
('^bar/$', 'redirect_to', {'url': None}),
urlpatterns = patterns('',
('^bar/$', redirect_to, {'url': None}),
) )
This example shows how ``"%"`` characters must be written in the URL in order 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 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:: string is written as ``"%7Ejacob/"`` (with only a single ``%``), an exception would be raised::
urlpatterns = patterns('django.views.generic.simple', from django.views.generic.simple import redirect_to
('^bar/$', 'redirect_to', {'url': '%%7Ejacob.'}),
urlpatterns = patterns('',
('^bar/$', redirect_to, {'url': '%%7Ejacob.'}),
) )
Date-based generic views Date-based generic views
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment