目录如下:
my_flasky
│ config.py
│ config.pyc
│ data-dev.sqlite
│ manage.py
│
└─app
│ models.py
│ models.pyc
│ __init__.py
│ __init__.pyc
│
├─auth
│ forms.py
│ forms.pyc
│ views.py
│ views.pyc
│ __init__.py
│ __init__.pyc
│
├─main
│ views.py
│ views.pyc
│ __init__.py
│ __init__.pyc
│
└─templates
│ base.html
│ index.html
│
└─auth
login.html
register.html
要实现登录,注册功能,需要实现的具体功能有:
1,数据库(SQLAlchemy):在app/models中构造User和Role模块,使用时只需要调用,代码如下:
#encoding:utf8
from werkzeug.security import generate_password_hash,check_password_hash
from . import db
from flask_login import UserMixin
from . import login_manager
class Role(db.Model):
#定义Role的数据库模型
__tablename__ = 'roles'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64), unique=True)
users = db.relationship('User', backref='role', lazy='dynamic')
def __repr__(self):
return '<Role %r>' % self.na