Last active
June 26, 2017 08:58
-
-
Save hannal/9de33b54a749457d7f29c5f30c5e9136 to your computer and use it in GitHub Desktop.
Django Template이 키나 속성에 대해 조용히 넘겨주지 않고 VariableDoesNotExist 내는 경우.
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
{{ apple|default:lemon.dictattr.color }} {# VariableDoesNotExist exception 발생 #} | |
<hr /> | |
{% with lemon.dictattr.color as colour %} | |
{{ apple|default:colour }} {# 문제 없음 #} | |
{% endwith %} | |
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
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