xxx
xxx

Reputation: 49

how to filled the data in django templates

I want to email a template in django. The template has one variable say name. I want to filled this value. How to do that. context is not working because i don't need to render the page.

Upvotes: 0

Views: 193

Answers (3)

luc
luc

Reputation: 43136

Try this

from django.template.loader import render_to_string
text = render_to_string('my_template.html', { 'name': 'xxx' })

Upvotes: 0

lprsd
lprsd

Reputation: 87185

context is not working because i don't need to render the page.

I guess what you are looking for is render_to_string shortcut.

Upvotes: 0

Daniel Roseman
Daniel Roseman

Reputation: 599926

Of course you need to render the template - and you do that via the context. How is it not working?

Upvotes: 1

Related Questions