Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes #2966 -- Added extra_context parameter to direct_to_template ge…

…neric view to keep it aligned with capabilities of other generic views. Thanks, wam-djangobug@wamber.net.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3950 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6d1335c0584c5a3b834915d00362427e4607755e 1 parent 5ec32a1
@freakboy3742 freakboy3742 authored
View
1  AUTHORS
@@ -160,6 +160,7 @@ answer newbie questions, and generally made Django that much better:
Amit Upadhyay
Geert Vanderkelen
Milton Waddams
+ wam-djangobug@wamber.net
Dan Watson <http://theidioteque.net/>
Rachel Willmer <http://www.willmer.com/kb/>
Gary Wilson <gary.wilson@gmail.com>
View
10 django/views/generic/simple.py
@@ -2,12 +2,18 @@
from django.template import RequestContext
from django.http import HttpResponse, HttpResponsePermanentRedirect, HttpResponseGone
-def direct_to_template(request, template, **kwargs):
+def direct_to_template(request, template, extra_context={}, **kwargs):
"""
Render a given template with any extra URL parameters in the context as
``{{ params }}``.
"""
- return render_to_response(template, {'params' : kwargs}, context_instance=RequestContext(request))
+ dictionary = {'params': kwargs}
+ for key, value in extra_context.items():
+ if callable(value):
+ dictionary[key] = value()
+ else:
+ dictionary[key] = value
+ return render_to_response(template, dictionary, context_instance=RequestContext(request))
def redirect_to(request, url, **kwargs):
"""
View
9 docs/generic_views.txt
@@ -92,6 +92,13 @@ which is a dictionary of the parameters captured in the URL.
* ``template``: The full name of a template to use.
+**Optional arguments:**
+
+ * ``extra_context``: A dictionary of values to add to the template
+ context. By default, this is an empty dictionary. If a value in the
+ dictionary is callable, the generic view will call it
+ just before rendering the template.
+
**Example:**
Given the following URL patterns::
@@ -171,7 +178,7 @@ a date in the *future* are not included unless you set ``allow_future`` to
template. By default, it's ``django.template.loader``.
* ``extra_context``: A dictionary of values to add to the template
- context. By default, this is an empty dictionary.
+ context. By default, this is an empty dictionary. If a value in the
dictionary is callable, the generic view will call it
just before rendering the template.

0 comments on commit 6d1335c

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