2013-02-11 81 views
0

我是初學者使用Python和flask.I想要的清單交給該名來自.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] }} 

但是這個代碼不work.It說:

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 
+0

你能展示完整的追溯? – 2013-02-11 21:30:38

+0

你能在你的文章中包含那個錯誤的完整回溯嗎? – 2013-02-11 21:31:04

+0

這裏是我的錯誤http://oi47.tinypic.com/2rg0r45.jpg – saidozcan 2013-02-11 21:34:06

回答

3

不能使用list作爲變量的名字,因爲list是Python中的保留關鍵字。

+0

這絕對看起來像最可能問題IMO – 2013-02-15 22:55:15