- Author:
- jasongreen
- Posted:
- December 30, 2009
- Language:
- Python
- Version:
- 1.1
- 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: [email protected]
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
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
new
keyword does not exist in Python...#
Please login first before commenting.