I was getting a VariableDoesNotExist
error with the following snippet when obj1.page
is None
.
{{ obj1.val1|default:obj1.page.val2 }}
Normally Django templates don't care about attribute accesses on None
values.
I was getting a VariableDoesNotExist
error with the following snippet when obj1.page
is None
.
{{ obj1.val1|default:obj1.page.val2 }}
Normally Django templates don't care about attribute accesses on None
values.
Django only cares about attribute lookups on None
values inside the default
template filter. I got around it using:
{% with obj1.page.val2 as val2 %}
{{ obj1.val1|default:val2 }}
{% endwith %}
VariableDoesNotExist bcoz it's not created in the session...so to create
views.py(in get method)
Variable_Name = request.session.get('Variable_Name') if not Variable_Name: request.session.Variable_Name = {}
#Here we create a dictionary