|
Revision 132, 1.2 kB
(checked in by akaihola, 3 years ago)
|
|
[shortcuts] Fixed indentation typo.
|
-
Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 | from django.http import HttpResponse |
|---|
| 2 | from django.template import RequestContext, loader |
|---|
| 3 | from django.shortcuts import render_to_response |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | def render_with_request_to_response(template, request, **kw): |
|---|
| 7 | """ |
|---|
| 8 | This function is provided for backwards compatibility. Use |
|---|
| 9 | ``render_rc_response()`` instead. |
|---|
| 10 | """ |
|---|
| 11 | return render_to_response(template, kw, RequestContext(request)) |
|---|
| 12 | |
|---|
| 13 | def render_rc_response(_rrr_template_name, |
|---|
| 14 | _rrr_request=None, |
|---|
| 15 | _rrr_mimetype=None, |
|---|
| 16 | **context): |
|---|
| 17 | """ |
|---|
| 18 | A nifty way to render templates with RequestContext as a HTTP response. |
|---|
| 19 | Example usage: |
|---|
| 20 | |
|---|
| 21 | >>> return render_rc_response('template.html', request, a=1, b=2) |
|---|
| 22 | >>> return render_rc_response('template.html', **locals()) |
|---|
| 23 | >>> return render_rc_response('template.html', {'request': request, 'a': 1}) |
|---|
| 24 | |
|---|
| 25 | If you're using ``**locals()``, remember to ``del varname`` for variables |
|---|
| 26 | you don't want in the context. |
|---|
| 27 | """ |
|---|
| 28 | if 'request' in context: |
|---|
| 29 | _rrr_request = context.pop('request') |
|---|
| 30 | doc = loader.render_to_string(_rrr_template_name, |
|---|
| 31 | context, |
|---|
| 32 | RequestContext(_rrr_request)) |
|---|
| 33 | return HttpResponse(doc, _rrr_mimetype) |
|---|