user7236255
user7236255

Reputation:

How to fill the variables in html template in django?

I want to pass "name" to html file and get the response instead of rendering the page. I want to send this html page via email after adding the "name".

<!DOCTYPE html>
<html>
<body>
<var>{{name}}</var>
</body>
</html>

Here is the django views code:

def sending(request):
    -- passing request.user --
    return_page = html_page(request.user)
    send_email(--email content--)

Can someone suggest me how to do this?

Upvotes: 1

Views: 557

Answers (1)

Bipul Jain
Bipul Jain

Reputation: 4643

You can use django render_to_string here.

Ex :

from django.template.loader import render_to_string
rendered = render_to_string('my_template.html', { 'foo': 'bar' })

Upvotes: 5

Related Questions