Last active
February 23, 2018 13:37
-
-
Save konradhalas/04208e05f62ed79eb67805c90c4c3ecc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
</head> | |
<body> | |
{{ person.name }} - {{ person.email }} <- autocompletion works like a charm | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
</head> | |
<body> | |
{{ person.name }} <- autocompletion doesn't work here | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import NamedTuple | |
from django.template.loader import get_template | |
class Person(NamedTuple): | |
name: str | |
email: str | |
def my_view(request): | |
if request.method == 'POST': | |
send_email() | |
return render( | |
request=request, | |
template_name='template_a.html', | |
context={ | |
'person': Person(name='John', email='[email protected]'), | |
} | |
) | |
def send_email(): | |
template = get_template('template_b.html') | |
content = template.render(context={ | |
'person': Person(name='John', email='[email protected]'), | |
}) | |
... # send content as email body, etc. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment