Я написал следующий код для регистрации пользователей в моем приложении:
@app.route('/register' , methods=['GET','POST'])
def register():
if request.method == 'GET':
return render_template('login/register.html')
user = User(username=request.form['username'], password=request.form['password'], email=request.form['email'], first_name="Sander", last_name="Bakker")
db.session.add(user)
db.session.commit()
flash('User successfully registered')
return redirect(url_for('login'))
Когда я отправляю почтовый запрос на регистрацию нового пользователя, используя представление реестра, я получаю следующую ошибку:
Traceback (most recent call last):
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/flask/app.py", line 2311, in wsgi_app
response = self.full_dispatch_request()
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/flask/app.py", line 1834, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/flask/app.py", line 1737, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/flask/_compat.py", line 36, in reraise
raise value
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/flask/app.py", line 1832, in full_dispatch_request
rv = self.dispatch_request()
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/flask/app.py", line 1818, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/root/Documents/projects/football/routes/home.py", line 15, in register
user = User(username=request.form['username'], password=request.form['password'], email=request.form['email'], first_name="Sander", last_name="Bakker")
File "<string>", line 2, in __init__
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/sqlalchemy/orm/instrumentation.py", line 373, in _new_state_if_none
state = self._state_constructor(instance, self)
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 855, in __get__
obj.__dict__[self.__name__] = result = self.fget(obj)
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/sqlalchemy/orm/instrumentation.py", line 199, in _state_constructor
self.dispatch.first_init(self, self.class_)
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/sqlalchemy/event/attr.py", line 297, in __call__
fn(*args, **kw)
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/sqlalchemy/orm/mapper.py", line 3341, in _event_on_first_init
configure_mappers()
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/sqlalchemy/orm/mapper.py", line 3229, in configure_mappers
mapper._post_configure_properties()
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/sqlalchemy/orm/mapper.py", line 1947, in _post_configure_properties
prop.init()
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/sqlalchemy/orm/interfaces.py", line 196, in init
self.do_init()
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/sqlalchemy/orm/relationships.py", line 1860, in do_init
self._process_dependent_arguments()
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/sqlalchemy/orm/relationships.py", line 1922, in _process_dependent_arguments
self.target = self.entity.persist_selectable
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 949, in __getattr__
return self._fallback_getattr(key)
File "/root/.local/share/virtualenvs/football-kyDuruyc/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 923, in _fallback_getattr
raise AttributeError(key)
AttributeError: entity
Кто-нибудь, кто может помочь мне с этой ошибкой?