diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2005-11-15 17:19:33 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2005-11-15 17:19:33 +0000 |
| commit | 400cf5658da46fc748e64a7570a6df0dd21cbff2 (patch) | |
| tree | eb727c17b90f281ac42d6eafa559d461bc6bbc28 /docs/generic_views.txt | |
| parent | dcb5bc32e0a475a514d3fdec8699c5fbe564b7ee (diff) | |
Added django.views.generic.simple.redirect_to view for issuing simple redirects. Also updated direct_to_template to use render_to_response to be consistant with coding style, and documented the simple generic views.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1249 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/generic_views.txt')
| -rw-r--r-- | docs/generic_views.txt | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/docs/generic_views.txt b/docs/generic_views.txt index 1c0de07a7a..9db1577d71 100644 --- a/docs/generic_views.txt +++ b/docs/generic_views.txt @@ -57,8 +57,8 @@ arguments may either come from the URL pattern (as ``month``, ``day``, ``year``, etc. do above) or from the additional-information dictionary (as for ``app_label``, ``module_name``, etc.). -All the generic views that follow require the ``app_label`` and ``module_name`` keys. -These values are easiest to explain through example:: +Most of the generic views that follow require the ``app_label`` and +``module_name`` keys. These values are easiest to explain through example:: >>> from django.models.blog import entries @@ -68,6 +68,42 @@ holds all your model definitions) and ``entries`` is the ``module_name`` of the ``module_name`` option of your model). In the docs below, these keys will not be repeated, but each generic view requires them. +Using "simple" generic views +============================ + +The ``django.views.generic.simple`` module contains simple views to handle a +couple of common cases: rendering a template when no view logic is needed, +and issuing a redirect. These views are: + +``direct_to_template`` + Renders a given template using any extra parameters passed in the + urlpattern; requires the ``template`` argument. + + For example, given the following URL patterns:: + + urlpatterns = patterns('django.views.generic.simple', + (r'^foo/$', 'direct_to_template', {'template' : 'foo_index'}), + (r'^foo/(?P<id>\d+)/$', 'direct_to_template', {'template' : 'foo_detail'}), + ) + + ... a request to ``/foo/`` would cause the ``foo_index`` template to be + rendered, and a request to ``/foo/15/`` would cause the ``foo_detail`` + template to be rendered with a context variable ``{{ params.id }}`` that is + set to ``15``. + +``redirect_to`` + Issue a redirect to a given URL. + + The given url may contain dict-style string formatting which will be + interpolated against the params in the URL. For example, to redirect from + ``/foo/<id>/`` to ``/bar/<id>/``, you could use the following urlpattern:: + + urlpatterns = patterns('django.views.generic.simple', + ('^foo/(?p<id>\d+)/$', 'redirect_to', {'url' : '/bar/%(id)s/'}), + ) + + If the given url is ``None``, a HttpResponseGone (410) will be issued. + Using date-based generic views ============================== @@ -322,3 +358,4 @@ The create/update/delete views are: object The object about to be deleted + |
