flask-admin TypeError:无法编译非模板节点

时间:2019-02-21 07:17:42

标签: python flask flask-admin

我正在关注youtube上的有关烧瓶管理工作的教程。现在,我只是想让它在route.py中工作,以查看它是否工作(我也尝试过模型,每次都会失败)。

这是我的代码

from flask_login import UserMixin
from flask_admin import Admin
from flask_admin.contrib.sqla import ModelView

class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20))
admin = Admin(app)
admin.add_view(ModelView(User, db.session))

在浏览器中执行http://127.0.0.1:5000/admin/时出现错误

builtins.TypeError
TypeError: Can't compile non template nodes

我花了最后3个小时来弄清楚发生了什么,但这没有任何意义,我在任何地方都找不到任何类似的问题。

追踪

Traceback (most recent call last):
        File "/Users/me/anaconda/lib/python3.6/site-packages/flask/app.py",   line 1997, in __call__
        return self.wsgi_app(environ, start_response)
      File "/Users/me/anaconda/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app
        response = self.handle_exception(e)
      File "/Users/me/anaconda/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception
        reraise(exc_type, exc_value, tb)
      File "/Users/me/anaconda/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
        raise value
      File "/Users/me/anaconda/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
        response = self.full_dispatch_request()
      File "/Users/me/anaconda/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "/Users/me/anaconda/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
        reraise(exc_type, exc_value, tb)
      File "/Users/me/anaconda/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
        raise value
      File "/Users/me/anaconda/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
        rv = self.dispatch_request()
      File "/Users/me/anaconda/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
        return self.view_functions[rule.endpoint](**req.view_args)
      File "/Users/me/anaconda/lib/python3.6/site-packages/flask_admin/base.py", line 69, in inner
        return self._run_view(f, *args, **kwargs)
      File "/Users/me/anaconda/lib/python3.6/site-packages/flask_admin/base.py", line 368, in _run_view
        return fn(self, *args, **kwargs)
      File "/Users/me/anaconda/lib/python3.6/site-packages/flask_admin/base.py", line 452, in index
        return self.render(self._template)
      File "/Users/me/anaconda/lib/python3.6/site-packages/flask_admin/base.py", line 308, in render
        return render_template(template, **kwargs)
      File "/Users/me/anaconda/lib/python3.6/site-packages/flask/templating.py", line 133, in render_template
        return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
      File "/Users/me/anaconda/lib/python3.6/site-packages/jinja2/environment.py", line 869, in get_or_select_template
        return self.get_template(template_name_or_list, parent, globals)
      File "/Users/me/anaconda/lib/python3.6/site-packages/jinja2/environment.py", line 830, in get_template
        return self._load_template(name, self.make_globals(globals))
      File "/Users/me/anaconda/lib/python3.6/site-packages/jinja2/environment.py", line 804, in _load_template
        template = self.loader.load(self, name, globals)
      File "/Users/me/anaconda/lib/python3.6/site-packages/jinja2/loaders.py", line 125, in load
        code = environment.compile(source, name, filename)
      File "/Users/me/anaconda/lib/python3.6/site-packages/jinja2/environment.py", line 581, in compile
        defer_init=defer_init)
      File "/Users/me/anaconda/lib/python3.6/site-packages/jinja2/environment.py", line 543, in _generate
        optimized=self.optimized)
      File "/Users/me/anaconda/lib/python3.6/site-packages/jinja2/compiler.py", line 78, in generate
        raise TypeError('Can\'t compile non template nodes')
    TypeError: Can't compile non template nodes

0 个答案:

没有答案