VariableDoesNotExist: Failed lookup for key

103 views
Skip to first unread message

Yang Liu

unread,
Dec 17, 2015, 7:04:30 AM12/17/15
to Django users
python 2.7.11 and django 1.9
I run the code in "python manage.py shell"

Django 1.9
In[2]:  import django
In[3]:  from django.template import Template, Context
In[4]:  t = Template("{% if x and x.strip %}OK{% else %}Empty{% endif %}")
In[5]: t.render(Context({}))
2015-12-17 14:13:43,443 [MainThread:3140] [django.template:923] [base:_resolve_lookup] [DEBUG]- Exception while resolving variable 'x' in template 'unknown'.
Traceback (most recent call last):
  File "D:\Python27\lib\site-packages\django\template\base.py", line 901, in _resolve_lookup
    (bit, current))  # missing attribute
VariableDoesNotExist: Failed lookup for key [x] in u"[{'False': False, 'None': None, 'True': True}, {}]"
Out[5]: u'Empty'

I use "if" in template,but it has excepiton.

Is it an bug?
Reply all
Reply to author
Forward
0 new messages