c#關於JWT跨域身份驗證的實現程式碼
阿新 • • 發佈:2020-11-27
from flask import Flask,render_template,request,redirect from flask_sqlalchemy import SQLAlchemy import config app = Flask(__name__) app.config.from_object(config) db=SQLAlchemy(app) class book(db.Model): __tablename__ = 'book' id = db.Column(db.Integer,primary_key=True,nullable=True) name= db.Column(db.String(100),nullable=True) author = db.Column(db.String(200),nullable=True) publish = db.Column(db.String(20),nullable=True) price = db.Column(db.String(20),nullable=True) types = db.Column(db.String(100),nullable=True) pages = db.Column(db.Integer, nullable=True) # 圖書管理系統@app.route('/') def login(): return render_template('login.html') # 圖書管理系統主頁面 @app.route('/index/') def index(): b = book.query.all() return render_template('index.html',b = b) # 新增頁面 @app.route('/addi/',methods = ["GET","POST"]) def addi(): if request.method == 'GET': return render_template('addi.html') else: name = request.form.get('name') author = request.form.get('author') publish = request.form.get('publish') price = request.form.get('price') types = request.form.get('types') pages = request.form.get('pages') bb = book(name = name,author = author,publish = publish,price = price,types = types,pages = pages) db.session.add(bb) db.session.commit() return redirect('/index/') # 刪除頁面 @app.route('/delete/<id>') def delete(id): b = book.query.filter(book.id == id).first() if b: db.session.delete(b) db.session.commit() return redirect('/index/') if __name__ == '__main__': db.drop_all() db.create_all() # 新增表資料 b1 = book(name = '網際網路思維',author = '趙大偉',publish = '2014-03-20',price = '49',typ es = 'it',pages= 280) b2 = book(name = '網際網路:從it到dt', author='阿里研究院', publish='2015-05-30', price='59', types='it', pages=285) b3 = book(name = '道德經', author='老子', publish='1955-01-14', price='88', types='國學', pages=81) db.session.add_all([b1,b2,b3]) db.session.commit() app.run(debug=True)