我正在将我的烧瓶应用程序中的字符串列表传递给 html 模板,在我尝试附加列表之前,它工作得非常好。我已经使用客户端 python 脚本测试了我对 append 方法的使用,它正在工作。我很困惑为什么我的列表附加会导致内部服务器错误。这是我的模板中使用参数的部分
<ul>
{% for file in files %}
<li>{{ file }}</li>
{% endfor %}
</ul>
这是我的烧瓶应用程序中的路线
@app.route('/')
def main():
FILES = [ 'test1', 'test2' ]
# Iterate through each file in the cloud storage container
for container in conn.get_account()[1]:
for data in conn.get_container(container['name'])[1]:
print 'object: {0}t size: {1}t date: {2}'.format(data['name'], data['bytes'], data['last_modified'])
FILES.append('test3')
return render_template('index.html', files = FILES)
FILES.append('test3') 行导致了问题,但我不知道为什么。当我注释掉这一行时,列表会按照您的预期传递给模板。
这是完整的追溯
Traceback (most recent call last):
File "/home/vcap/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/home/vcap/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/vcap/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/vcap/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/vcap/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/vcap/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/vcap/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/vcap/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/vcap/app/server.py", line 93, in main
for container in conn.get_account()[1]:
File "/home/vcap/app/.heroku/python/lib/python2.7/site-packages/swiftclient/client.py", line 1615, in get_account
full_listing=full_listing)
File "/home/vcap/app/.heroku/python/lib/python2.7/site-packages/swiftclient/client.py", line 1553, in _retry
self.url, self.token = self.get_auth()
File "/home/vcap/app/.heroku/python/lib/python2.7/site-packages/swiftclient/client.py", line 1507, in get_auth
timeout=self.timeout)
File "/home/vcap/app/.heroku/python/lib/python2.7/site-packages/swiftclient/client.py", line 617, in get_auth
auth_version=auth_version)
File "/home/vcap/app/.heroku/python/lib/python2.7/site-packages/swiftclient/client.py", line 517, in get_auth_keystone
ksclient, exceptions = _import_keystone_client(auth_version)
File "/home/vcap/app/.heroku/python/lib/python2.7/site-packages/swiftclient/client.py", line 502, in _import_keystone_client
variables to be set or overridden with -A, -U, or -K.''')
ClientException:
Auth versions 2.0 and 3 require python-keystoneclient, install it or use Auth
version 1.0 which requires ST_AUTH, ST_USER, and ST_KEY environment
variables to be set or overridden with -A, -U, or -K.
似乎附加并没有导致错误,而是暴露了一个错误。整理好后我会更新。