私はpythonとフラスコの初心者です.pyファイルからビューファイルにリストを渡したかったのですが、これを行いました:
python ファイル:
@app.route('/admin',methods=['GET'])
def panelSettings():
myList = ["gan","dalf"]
return render_template('admin.html',list=myList)
html ファイル:
my list's first eleman is:{{ list[0] }}
ただし、このコードは機能しません。
myList is not defined
私の目的は、複数の変数をビューに渡すことでした。どうすればよいですか?
私のトレースバックは次のとおりです。
Traceback (most recent call last):
File "/Users/ozcan/flask/flask/app.py", line 1823, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/ozcan/flask/flask/app.py", line 1811, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/ozcan/flask/flask/app.py", line 1809, in wsgi_app
response = self.full_dispatch_request()
File "/Users/ozcan/flask/flask/app.py", line 1482, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/ozcan/flask/flask/app.py", line 1480, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/ozcan/flask/flask/app.py", line 1466, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/ozcan/Documents/python/app.py", line 104, in panel
return render_template("panel.html",route=route)
File "/Users/ozcan/flask/flask/templating.py", line 127, in render_template
context, ctx.app)
File "/Users/ozcan/flask/flask/templating.py", line 109, in _render
rv = template.render(context)
File "/Users/ozcan/flask/venv/lib/python2.7/site-packages/Jinja2-2.6- py2.7.egg/jinja2/environment.py", line 894, in render
return self.environment.handle_exception(exc_info, True)
File "/Users/ozcan/Documents/python/templates/panel.html", line 1, in top-level template code
{% extends "layout.html" %}
File "/Users/ozcan/Documents/python/templates/layout.html", line 62, in top-level template code
{%block panel%}{%endblock%}
File "/Users/ozcan/Documents/python/templates/panel.html", line 11, in block "panel"
{{ list[0]}}
File "/Users/ozcan/flask/venv/lib/python2.7/site-packages/Jinja2-2.6-py2.7.egg/jinja2/environment.py", line 353, in getitem
return obj[argument]
UndefinedError: 'list' is undefined