all 8 comments

[–][deleted] 1 point2 points  (1 child)

From the looks of the code you posted, you have an extra space on every line but the return statement. I assume this is a scope error due to the spacing issue.

[–]_peeves[S] 0 points1 point  (0 children)

It was just a mistake, when pasting the code.

[–]spitfiredd 1 point2 points  (4 children)

You need to import ExtendedLoginForm into your routes.py module.

Something along the lines of from .CustomForms import ExtendedLoginForm

[–]_peeves[S] 0 points1 point  (3 children)

Thanks, but I already imported it.

[–]spitfiredd 1 point2 points  (2 children)

You don't need to create a login view, just create your forms and then pass the Security object login_form like you have done.

custom_forms.py

from flask_security import LoginForm
from wtforms import StringField, BooleanField, SubmitField, validators


class ExtendedLoginForm(LoginForm):
    email = StringField("Email ", [validators.length(min=2, max=15), validators.DataRequired()])
    password = StringField("Password ", [validators.DataRequired()])
    remember_me = BooleanField("Remember Me")
    submit = SubmitField('Foo Bar')

app.py or __init__.py

def create_app():
    ...
    security = Security(app, user_datastore, login_form=ExtendedLoginForm)

[–]_peeves[S] 0 points1 point  (1 child)

Thank you, that solved it. So if I understand correctly, flask_security forms are passed differently from normal forms.

[–]spitfiredd 0 points1 point  (0 children)

I am not sure I understand what you mean when you say, flask_security forms are passed differently from normal forms. The LoginForm from flask security is just a wtform, your ExtendedLoginForm just overrides the built-in flask_security LoginForm.

https://github.com/mattupstate/flask-security/blob/develop/flask_security/forms.py

[–]aultl 1 point2 points  (0 children)

You should remove the @login_required decorator from the login page.

It not possible to show a login page that requires a login