Skip to content

Instantly share code, notes, and snippets.

@konradhalas
Last active February 23, 2018 13:37
Show Gist options
  • Save konradhalas/04208e05f62ed79eb67805c90c4c3ecc to your computer and use it in GitHub Desktop.
Save konradhalas/04208e05f62ed79eb67805c90c4c3ecc to your computer and use it in GitHub Desktop.
<!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>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
{{ person.name }} <- autocompletion doesn't work here
</body>
</html>
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