Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- django template - parse variable inside string variable
- vars['current_city'] = "London"
- vars['content'] = 'the current city is: {{current_city}}' #this string comes from db
- return render_template(request, 'about_me.html',vars)
- {{content}}
- from django.template import Template, Context
- ...
- context = {
- 'current_city': 'London'
- }
- db_template = Template('the current city is: {{current_city}}') # get from db
- context['content'] = db_template.render(Context(context))
- return render_template(request, 'about_me.html', context)
- simple_cache = {}
- def fooview(request):
- context = {
- 'current_city': 'London'
- }
- db_template_string = 'the current city is: {{current_city}}'
- if simple_cache.has_key(db_template_string):
- db_template = simple_cache.get(db_template_string)
- else:
- simple_cache[db_template_string] = Template(db_template_string)
- context['content'] = db_template.render(Context(context))
- return render_template(request, 'about_me.html', context)
Add Comment
Please, Sign In to add comment