Add google appengine to repo
[frozenviper.git] / google_appengine / lib / django / django / views / generic / simple.py
blob355bd25ef8306a1c7a7ce43867ce29e2affb3fb2
1 from django.shortcuts import render_to_response
2 from django.template import RequestContext
3 from django.http import HttpResponse, HttpResponsePermanentRedirect, HttpResponseGone
5 def direct_to_template(request, template, extra_context={}, **kwargs):
6 """
7 Render a given template with any extra URL parameters in the context as
8 ``{{ params }}``.
9 """
10 dictionary = {'params': kwargs}
11 for key, value in extra_context.items():
12 if callable(value):
13 dictionary[key] = value()
14 else:
15 dictionary[key] = value
16 return render_to_response(template, dictionary, context_instance=RequestContext(request))
18 def redirect_to(request, url, **kwargs):
19 """
20 Redirect to a given URL.
22 The given url may contain dict-style string formatting, which will be
23 interpolated against the params in the URL. For example, to redirect from
24 ``/foo/<id>/`` to ``/bar/<id>/``, you could use the following URLconf::
26 urlpatterns = patterns('',
27 ('^foo/(?P<id>\d+)/$', 'django.views.generic.simple.redirect_to', {'url' : '/bar/%(id)s/'}),
30 If the given url is ``None``, a HttpResponseGone (410) will be issued.
31 """
32 if url is not None:
33 return HttpResponsePermanentRedirect(url % kwargs)
34 else:
35 return HttpResponseGone()