Skip to content

Instantly share code, notes, and snippets.

@hannal
Last active June 26, 2017 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hannal/9de33b54a749457d7f29c5f30c5e9136 to your computer and use it in GitHub Desktop.
Save hannal/9de33b54a749457d7f29c5f30c5e9136 to your computer and use it in GitHub Desktop.
Django Template이 키나 속성에 대해 조용히 넘겨주지 않고 VariableDoesNotExist 내는 경우.
{{ apple|default:lemon.dictattr.color }} {# VariableDoesNotExist exception 발생 #}
<hr />
{% with lemon.dictattr.color as colour %}
{{ apple|default:colour }} {# 문제 없음 #}
{% endwith %}
def fruits(request):
lemon.dictattr = {}
ctx = {
'lemon': lemon,
}
return render(request, 'fruits.html', ctx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment