Answer the question
In order to leave comments, you need to log in
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
@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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question