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
):
7 Render a given template with any extra URL parameters in the context as
10 dictionary
= {'params': kwargs
}
11 for key
, value
in extra_context
.items():
13 dictionary
[key
] = value()
15 dictionary
[key
] = value
16 return render_to_response(template
, dictionary
, context_instance
=RequestContext(request
))
18 def redirect_to(request
, url
, **kwargs
):
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.
33 return HttpResponsePermanentRedirect(url
% kwargs
)
35 return HttpResponseGone()