Here's my template:
<form action="{{ url_for('parse_grammar') }}" method="post">
<p>Enter sentence:
<p><input type=text name=sentence value="{{ sentence }}">
<p><input type=submit value=Parse>
</form>
{% if error %}
<p>Could not parse</p>
{% elif grammar != None %}
<p>{{ grammar }}</p>
<ul class="grammar_tree">
{%- for item in grammar recursive %}
<li>{{ item[0] }}
{%- if isinstance(item[1], str) %}
{{ item[1] }}
{%- else %}
<ul class="submenu">{{ loop(item[1]) }}</ul>
{%- endif %}</li>
{%- endfor %}
</ul>
{% endif %}
And here's the error I'm getting in my log:
2017-02-09 22:37:40,822 :[2017-02-09 22:37:40,814] ERROR in app: Exception on /grammar/ [POST]
2017-02-09 22:37:40,823 :Traceback (most recent call last):
2017-02-09 22:37:40,823 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app
2017-02-09 22:37:40,823 : response = self.full_dispatch_request()
2017-02-09 22:37:40,823 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request
2017-02-09 22:37:40,823 : rv = self.handle_user_exception(e)
2017-02-09 22:37:40,823 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception
2017-02-09 22:37:40,823 : reraise(exc_type, exc_value, tb)
2017-02-09 22:37:40,823 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
2017-02-09 22:37:40,823 : raise value
2017-02-09 22:37:40,824 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
2017-02-09 22:37:40,824 : rv = self.dispatch_request()
2017-02-09 22:37:40,824 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
2017-02-09 22:37:40,824 : return self.view_functions[rule.endpoint](**req.view_args)
2017-02-09 22:37:40,824 : File "./hello.py", line 78, in parse_grammar
2017-02-09 22:37:40,824 : return render_template('parse_grammar.html', grammar=grammar, sentence=sentence, error=error)
2017-02-09 22:37:40,824 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/flask/templating.py", line 134, in render_template
2017-02-09 22:37:40,824 : context, ctx.app)
2017-02-09 22:37:40,824 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/flask/templating.py", line 116, in _render
2017-02-09 22:37:40,824 : rv = template.render(context)
2017-02-09 22:37:40,824 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/jinja2/environment.py", line 1008, in render
2017-02-09 22:37:40,824 : return self.environment.handle_exception(exc_info, True)
2017-02-09 22:37:40,824 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/jinja2/environment.py", line 780, in handle_exception
2017-02-09 22:37:40,825 : reraise(exc_type, exc_value, tb)
2017-02-09 22:37:40,825 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/jinja2/_compat.py", line 37, in reraise
2017-02-09 22:37:40,825 : raise value.with_traceback(tb)
2017-02-09 22:37:40,825 : File "/home/tess/mysite/templates/parse_grammar.html", line 11, in top-level template code
2017-02-09 22:37:40,826 : {%- for item in grammar recursive %}
2017-02-09 22:37:40,826 : File "/home/tess/mysite/templates/parse_grammar.html", line 13, in template
2017-02-09 22:37:40,826 : {%- if isinstance(item[1], str) %}
2017-02-09 22:37:40,826 :jinja2.exceptions.UndefinedError: 'isinstance' is undefined
2017-02-09 22:37:40,975 :[2017-02-09 22:37:40,975] ERROR in app: Exception on /grammar/ [POST]
2017-02-09 22:37:40,975 :Traceback (most recent call last):
2017-02-09 22:37:40,975 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app
2017-02-09 22:37:40,975 : response = self.full_dispatch_request()
2017-02-09 22:37:40,976 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request
2017-02-09 22:37:40,976 : rv = self.handle_user_exception(e)
2017-02-09 22:37:40,976 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception
2017-02-09 22:37:40,976 : reraise(exc_type, exc_value, tb)
2017-02-09 22:37:40,976 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
2017-02-09 22:37:40,976 : raise value
2017-02-09 22:37:40,976 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
2017-02-09 22:37:40,976 : rv = self.dispatch_request()
2017-02-09 22:37:40,976 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
2017-02-09 22:37:40,976 : return self.view_functions[rule.endpoint](**req.view_args)
2017-02-09 22:37:40,976 : File "./hello.py", line 78, in parse_grammar
2017-02-09 22:37:40,976 : return render_template('parse_grammar.html', grammar=grammar, sentence=sentence, error=error)
2017-02-09 22:37:40,976 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/flask/templating.py", line 134, in render_template
2017-02-09 22:37:40,976 : context, ctx.app)
2017-02-09 22:37:40,977 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/flask/templating.py", line 116, in _render
2017-02-09 22:37:40,977 : rv = template.render(context)
2017-02-09 22:37:40,977 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/jinja2/environment.py", line 1008, in render
2017-02-09 22:37:40,977 : return self.environment.handle_exception(exc_info, True)
2017-02-09 22:37:40,977 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/jinja2/environment.py", line 780, in handle_exception
2017-02-09 22:37:40,977 : reraise(exc_type, exc_value, tb)
2017-02-09 22:37:40,977 : File "/home/tess/.virtualenvs/my-virtualenv/lib/python3.5/site-packages/jinja2/_compat.py", line 37, in reraise
2017-02-09 22:37:40,977 : raise value.with_traceback(tb)
2017-02-09 22:37:40,977 : File "/home/tess/mysite/templates/parse_grammar.html", line 11, in top-level template code
2017-02-09 22:37:40,978 : {%- for item in grammar recursive %}
2017-02-09 22:37:40,978 : File "/home/tess/mysite/templates/parse_grammar.html", line 13, in template
2017-02-09 22:37:40,978 : {%- if isinstance(item[1], str) %}
2017-02-09 22:37:40,978 :jinja2.exceptions.UndefinedError: 'isinstance' is undefined
Can anyone help me out with why it doesn't recognize the built in function isinstance? Thanks!