当前位置:   article > 正文

flask login mysql_Flask连接mysql,实现页面登录

flask-login mysql

主要代码:

from flask import Flask,request,g,session,flash,redirect,url_for,render_template

from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)

app.config[‘SQLALCHEMY_DATABASE_URI‘] = ‘mysql+pymysql://root:12345678@localhost/mydb‘

app.config[‘SQLALCHEMY_COMMIT_ON_TEARDOWN‘] = True

app.config[‘SQLALCHEMY_TRACK_MODIFICATIONS‘] = False

db = SQLAlchemy(app)

class User(db.Model):

class User(db.Model):

__tablename__ = ‘user‘

id = db.Column(db.Integer, primary_key=True, autoincrement=True, nullable=False)

name = db.Column(db.String(20), nullable=False)

password = db.Column(db.String(30), nullable=False)

def __repr__(self):

return ‘User:%s‘%self.name

db.create_all()

@app.route(‘/login‘,methods=[‘POST‘,‘GET‘])

def logi

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/483377
推荐阅读
相关标签
  

闽ICP备14008679号