base.py:
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import Column, SmallInteger, Integer
db = SQLAlchemy()
class Base(db.Model):
__abstract__ = True
# create_time = Column('create_time',Integer)
status = Column(SmallInteger,default=1 )
def set_attrs(self,attrs_dict):
for key,value in attrs_dict.items():
if hasattr(self,key) and key != 'id':
setattr(self,key,value)
auth.py:
from app.forms.auth import RegisterForm ,LoginForm
from app.models.base import db
from . import web
from app.models.user import User
from flask import render_template, redirect, request, url_for, flash
from werkzeug.security import generate_password_hash
@web.route('/register',methods = ['GET','POST'])
def register():
form = RegisterForm(request.form)
if request.method == 'POST' and form.validate():
user = User()
user.set_attrs(form.data)
db.session.add(user)
db.session.commit()
redirect(url_for('web.login'))
# user.password = generate_password_hash(form.password.data)
# user.nickname = form.nickname.data
# request.form
return render_template('auth/register.html',form = form)