Proper translation while rendering template
Sometimes you do not render templates from views (with the request
object as part of the context). For instance, if you render emails from a method or function elsewhere. To properly pass the user's LANGUAGE_CODE
context variable to your template renderization:
def _render_tmpl(self, template):
from django.utils import translation
ctxt['LANGUAGE_CODE'] = translation.get_language()
return render_to_string(template, ctxt)
Written by Hector Garcia
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Templates
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#