我不能为我的生活找出造成这种语法错误的原因,我一直在查看我的代码,我无法弄明白,因为它在一段时间之前工作得很好。它只是第156行(第二行到最后一行的if 名称 ==“主要”: app.run)
from flask import Flask, render_template
import sqlite3 as sql
import sqlite3
DATABASE = 'database.db'
app = Flask(__name__)
app.config.from_object(__name__)
app.run(debug=True)
def connect_db():
return sqlite3.connect(app.config[DATABASE])
@app.route('/')
def index():
con = sqlite3.connect("database.db")
con.row_factory = sqlite3.Row
cur = con.cursor()
cur.execute("select * from products")
rows = cur.fetchall();
return render_template('Index.html', rows=rows)
@app.route('/Purchase')
def Product_9():
if request.method == 'POST':
try:
name = request.form['name']
address = request.form['address']
creditcard = request.form['creditcard']
seccode = request.form['seccode']
quantity = request.form['quantity']
with sql.connect("database.db") as con:
cur = con.cursor()
cur.execute("INSERT INTO purchase (name,addr,city,pin) VALUES (?,?,?,?)",(name,address,creditcard,seccode,quantity) )
con.commit()
msg = "Record successfully added"
return render_template('Purchase.html', rows=rows)
if __name__ == "__main__":
app.run()
答案 0 :(得分:1)
如果错误不在行中,则必须由之前的某些内容引起。
在这种情况下,错误为IndentationError: unexpected unindent
,因为您try:
没有except
或finally
。