不确定我做错了什么。我正在关注flask-admin的快速入门指南(link),并尝试运行初始化section下提供的基本示例。当我运行该代码并浏览到localhost:5000 / admin /我收到以下错误
builtins.AttributeError
AttributeError:'For'对象没有属性'test'
如果有帮助,我可以粘贴详细的异常堆栈。
我怀疑缺少依赖项并尝试重新安装flask-admin,但它没有帮助。这是我的点子冻结输出:
$ pip freeze
APScheduler==3.3.1
click==6.7
dominate==2.3.1
Flask==0.12.2
Flask-Admin==1.5.0
Flask-APScheduler==1.7.0
Flask-Bootstrap==3.3.7.1
Flask-SQLAlchemy==2.2
itsdangerous==0.24
Jinja2==2.9.6
MarkupSafe==1.0
python-dateutil==2.6.1
pytz==2017.2
six==1.10.0
SQLAlchemy==1.1.13
SQLAlchemy-Utils==0.32.14
tzlocal==1.4
visitor==0.1.3
Werkzeug==0.12.2
WTForms==2.1
我正在使用python 3.6.1
我的代码与示例完全相同:
from flask import Flask
from flask.ext.admin import Admin
app = Flask(__name__)
admin = Admin(app)
app.run()
这是异常堆栈:
Traceback (most recent call last):
File "c:\project\.venv\lib\site-packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "c:\project\.venv\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "c:\project\.venv\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "c:\project\.venv\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "c:\project\.venv\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "c:\project\.venv\lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "c:\project\.venv\lib\site-packages\flask_admin\base.py", line 69, in inner
return self._run_view(f, *args, **kwargs)
File "c:\project\.venv\lib\site-packages\flask_admin\base.py", line 368, in _run_view
return fn(self, *args, **kwargs)
File "c:\project\.venv\lib\site-packages\flask_admin\base.py", line 452, in index
return self.render(self._template)
File "c:\project\.venv\lib\site-packages\flask_admin\base.py", line 308, in render
return render_template(template, **kwargs)
File "c:\project\.venv\lib\site-packages\flask\templating.py", line 134, in render_template
context, ctx.app)
File "c:\project\.venv\lib\site-packages\flask\templating.py", line 116, in _render
rv = template.render(context)
File "c:\project\.venv\lib\site-packages\jinja2\asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "c:\project\.venv\lib\site-packages\jinja2\environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "c:\project\.venv\lib\site-packages\jinja2\environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "c:\project\.venv\lib\site-packages\jinja2\_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "c:\project\.venv\lib\site-packages\flask_admin\templates\bootstrap2\admin\index.html", line 1, in top-level template code
{% extends 'admin/master.html' %}
File "c:\project\.venv\lib\site-packages\flask_admin\templates\bootstrap2\admin\master.html", line 1, in top-level template code
{% extends admin_base_template %}
File "c:\project\.venv\lib\site-packages\jinja2\environment.py", line 543, in _generate
optimized=self.optimized)
File "c:\project\.venv\lib\site-packages\jinja2\compiler.py", line 82, in generate
generator.visit(node)
File "c:\project\.venv\lib\site-packages\jinja2\visitor.py", line 38, in visit
return f(node, *args, **kwargs)
File "c:\project\.venv\lib\site-packages\jinja2\compiler.py", line 772, in visit_Template
self.blockvisit(block.body, block_frame)
File "c:\project\.venv\lib\site-packages\jinja2\compiler.py", line 372, in blockvisit
self.visit(node, frame)
File "c:\project\.venv\lib\site-packages\jinja2\visitor.py", line 38, in visit
return f(node, *args, **kwargs)
File "c:\project\.venv\lib\site-packages\jinja2\compiler.py", line 1130, in visit_If
self.blockvisit(node.body, if_frame)
File "c:\project\.venv\lib\site-packages\jinja2\compiler.py", line 372, in blockvisit
self.visit(node, frame)
File "c:\project\.venv\lib\site-packages\jinja2\visitor.py", line 38, in visit
return f(node, *args, **kwargs)
File "c:\project\.venv\lib\site-packages\jinja2\compiler.py", line 1014, in visit_For
if node.test:
AttributeError: 'For' object has no attribute 'test'
欢迎任何建议。
答案 0 :(得分:0)
我怀疑我以某种方式弄乱了我的venv。我再次尝试使用全新的venv,安装所有包装,现在一切正常。希望这有助于某人。