Login

simplified render_to_response with RequestContext

Author:
jasongreen
Posted:
December 30, 2009
Language:
Python
Version:
1.1
Tags:
shortcuts simplified
Score:
0 (after 0 ratings)

manything need to do with RequestContext, but it's too tedious. use render_to_response("/my.html", {'key':value,},request) instead of render_to_response("/my.html", {'key':value,},new RequestContext(request)) and you can also use render_to_response("/my.html", {'key':value,},new RequestContext(request))

 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 8 years, 6 months ago
  2. render_with decorator by tobias 6 years, 11 months ago
  3. render_to by asolovyov 7 years, 2 months ago
  4. another render_to_response wrapper by ro60 7 years, 8 months ago
  5. Caching XHTML render_to_response by smoonen 7 years, 1 month ago

Comments

romain-hardouin (on January 7, 2010):

new keyword does not exist in Python...

#

Please login first before commenting.