我试图制作一个全功能的Web应用程序,其中包括使用WTForms作为数据库资源,我为此感到困惑,
jinja2.exceptions.UndefinedError: 'wtforms.fields.core.StringField object' has no attribute 'username'
Traceback (most recent call last):
File "/Users/lkendon/flaskblog/venv/lib/python3.7/site-packages/flask/app.py", line 2328, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/lkendon/flaskblog/venv/lib/python3.7/site-packages/flask/app.py", line 2314, in wsgi_app
response = self.handle_exception(e)
File "/Users/lkendon/flaskblog/venv/lib/python3.7/site-packages/flask/app.py", line 1760, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/lkendon/flaskblog/venv/lib/python3.7/site-packages/flask/_compat.py", line 36, in reraise
raise value
File "/Users/lkendon/flaskblog/venv/lib/python3.7/site-packages/flask/app.py", line 2311, in wsgi_app
response = self.full_dispatch_request()
File "/Users/lkendon/flaskblog/venv/lib/python3.7/site-packages/flask/app.py", line 1834, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/lkendon/flaskblog/venv/lib/python3.7/site-packages/flask/app.py", line 1737, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/lkendon/flaskblog/venv/lib/python3.7/site-packages/flask/_compat.py", line 36, in reraise
raise value
File "/Users/lkendon/flaskblog/venv/lib/python3.7/site-packages/flask/app.py", line 1832, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/lkendon/flaskblog/venv/lib/python3.7/site-packages/flask/app.py", line 1818, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/lkendon/flaskblog/flaskblog.py", line 36, in register
return render_template('register.html', title='Register', form=form)
File "/Users/lkendon/flaskblog/venv/lib/python3.7/site-packages/flask/templating.py", line 135, in render_template
context, ctx.app)
File "/Users/lkendon/flaskblog/venv/lib/python3.7/site-packages/flask/templating.py", line 117, in _render
rv = template.render(context)
File "/Users/lkendon/flaskblog/venv/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/Users/lkendon/flaskblog/venv/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/Users/lkendon/flaskblog/venv/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/lkendon/flaskblog/venv/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "/Users/lkendon/flaskblog/templates/register.html", line 1, in top-level template code
{% extends "layout.html" %}
File "/Users/lkendon/flaskblog/templates/layout.html", line 41, in top-level template code
{% block content %}{% endblock %}
File "/Users/lkendon/flaskblog/templates/register.html", line 10, in block "content"
{{form.username.username(class="form-control form-control-lg")}}
jinja2.exceptions.UndefinedError: 'wtforms.fields.core.StringField object' has no attribute 'username'
这到底是什么问题,我正在学习一个教程,并且通过提供的摘要输入了相同的详细信息。
答案 0 :(得分:1)
查看回溯,您正在呼叫{{form.username.username(...
,该电话应为{{form.username(...