Create a gist now

Instantly share code, notes, and snippets.

@hannal /fruits.html
Last active Jun 26, 2017

What would you like to do?
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