simplified render_to_response with RequestContext

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# coding:utf-8
'''
Created on 2009-12-31

@author: Jason Green
@author-email: guileen@gmail.com

use
`return render_to_response("/my.html", {'key':value,},request)`
instead of
`return render_to_response("/my.html", {'key':value,},new RequestContext(request))`
and you can also use
`return render_to_response("/my.html", {'key':value,},new RequestContext(request))`
'''
import django.template.loader as djloader
from django.template.loader import render_to_string as _original_render_to_string
from django.template.context import RequestContext
def render_to_string(template_name, dictionary=None, context_instance=None):
    if isinstance(context_instance,HttpRequest):
        context_instance = RequestContext(context_instance)
    return _original_render_to_string(template_name, dictionary, context_instance)
djloader.render_to_string = render_to_string

More like this

  1. render_to_response wrapper by Magus 7 years, 1 month ago
  2. render_with decorator by tobias 5 years, 7 months ago
  3. render_to by asolovyov 5 years, 10 months ago
  4. Caching XHTML render_to_response by smoonen 5 years, 9 months ago
  5. another render_to_response wrapper by ro60 6 years, 3 months ago

Comments

Romain Hardouin (on January 7, 2010):

new keyword does not exist in Python...

#

(Forgotten your password?)