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 创建数据库,但它给了我这个错误
名称错误:名称“请求”未定义
您需要导入请求:
from flask import Flask, render_template, request