如何使用sqlite和flask创建数据库?

问题描述 投票:0回答:1

from flask import Flask , render_template
import sqlite3 as db

myapp = Flask(__name__)

@myapp.route("/")
def creat_database():
    return render_template("home.html")

@myapp.route("/createdatabase",methods = ['POST','GET'])
def createdatabase():
    if request.method == 'POST':
        try:
            name = request.form['database']
            
            with db.connect(name) as con :
                msg = "Database Created Succesfully"
        except:
            con.rollback()
            msg = "Error To Create Database"
        finally:
            con.close()
            return render_template("result.html",msg = msg)
        
if (__name__)==("__main__"):
    myapp.run(debug= True , port=8900)
        

我尝试使用 sqlite 和 Flask 创建数据库,但它给了我这个错误

名称错误:名称“请求”未定义

python database sqlite flask
1个回答
0
投票

您需要导入请求:

from flask import Flask, render_template, request
© www.soinside.com 2019 - 2024. All rights reserved.