flask-security中注册页面上的其他字段
我正在尝试在我的Flask应用程序中创建一个注册页面.我正在使用Flask-Security进行用户管理.我已经正确设置了;标准注册页面可以正确呈现.但是,我的模型包含许多额外的必填字段,因此我需要更新视图.
I am trying to make a registration page in my Flask application. I am using Flask-Security for user management. I have set it up properly; the standard registration page did render correctly. However, my model consists of quite a few extra, required fields, so I needed to update the view.
我的security_config文件如下所示:
My security_config file looks as follows:
from models import *
from flask_security.forms import ConfirmRegisterForm, Required
class ExtendedConfirmRegisterForm(ConfirmRegisterForm):
first_name = CharField('Voornaam', [Required()])
last_name = CharField('Achternaam', [Required()])
# Setup Flask-Security
user_datastore = PeeweeUserDatastore(db, Student, Role, StudentRoleRel)
security = Security(app, user_datastore,
confirm_register_form=ExtendedConfirmRegisterForm)
我的表单:
{% extends "base.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field %}
{% include "security/_messages.html" %}
{% block main%}
<h1>Registreer</h1>
<form action="{{ url_for_security('register') }}" method="POST" name="register_user_form">
{{ register_user_form.hidden_tag() }}
{{ render_field(register_user_form.first_name) }}
{{ render_field(register_user_form.last_name) }}
{{ render_field_with_errors(register_user_form.email) }}
{{ render_field_with_errors(register_user_form.password) }}
{% if register_user_form.password_confirm %}
{{ render_field_with_errors(register_user_form.password_confirm) }}
{% endif %}
{{ render_field(register_user_form.submit) }}
</form>
{% endblock %}
当我尝试打开注册页面时,出现以下错误:
When I try to open the register page, I get the following error:
AttributeError: 'CharField' object has no attribute '__call__'
我真的不知道该如何进行.我该如何解决这个问题?
I don't really know how to proceed. How can I resolve this issue?
如果您得到类似的信息: jinja2.exceptions.UndefinedError:'flask_security.forms.ConfirmRegisterForm对象'没有属性'first_name'
If you are getting something like: jinja2.exceptions.UndefinedError: 'flask_security.forms.ConfirmRegisterForm object' has no attribute 'first_name'
然后可能是由于 SECURITY_CONFIRMABLE
而引起的,您将其设置为true,这意味着flask将使用其他形式.更多详细信息: https://github.com/mattupstate/flask-security/issues/54
Then it is likely due to SECURITY_CONFIRMABLE
, you set that to true which means flask will use a different form. More details: https://github.com/mattupstate/flask-security/issues/54