Z
Z
zigen2014-11-10 17:24:39
Flask
zigen, 2014-11-10 17:24:39

How to organize user registration in Flask?

Good afternoon.
Show an example of registering users in Flask by login\password?
Only such stupidity came to mind:

Model:

class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key = True)
    email = Column(String(120), unique = True)
    password = Column(String(64))
    role = Column(Integer, default = ROLE_USER)
    posts = relationship('Post', backref = 'author', lazy = 'dynamic')
    def __init__(self, email=None, password=None):
        self.email = email
        self.password = password


View:

@app.route('/register', methods = ['GET', 'POST'])
def login():
    form = LoginForm()
    if form.validate_on_submit():
        u = User(form.login.data, hashlib.md5((form.password.data).encode('UTF-8')).hexdigest())
        db_session.add(u)
        db_session.commit()
        return redirect('/index')
    return render_template('register.html',
        title = 'Registration',
        form = form)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
snoopt, 2014-11-21
@snoopt

Flask
login is a very flexible solution. Easily customized for specific tasks.
Flask security works out of the box here. Based on the first extension and several others.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question