我在尝试从数据库中删除数据时遇到问题。我找不到我要删除的代码的任何问题。插入数据可以很好地工作,但是删除数据使我无法正常工作。这是我的路线,显示插入和删除数据。
@app.route('/our-ma/addsite', methods=['POST', 'GET'])
def addsite():
cur = mysql.connection.cursor()
sites = cur.execute('Select * from site_info')
data = cur.fetchall()
cur.close()
form = Edit_Delete()
addForm = SiteInfo()
if request.method == 'POST':
if form.validate_on_submit():
mycur = mysql.connection.cursor()
# print("This is the site to delete:", form.site.data)
sql = f"""delete from site_info where site_name="{{form.site.data}}"; """
mycur.execute(sql)
mycur.connection.commit()
sites = mycur.execute('select * from site_info')
data = mycur.fetchall()
for x in data:
print(x)
mycur.close()
return render_template('add_site.html', title='Add Site', data=data, form = form, addForm=addForm)
if addForm.validate_on_submit():
print("This addsite form is being called right now.")
specialnotes = request.form['specialnotes']
cur = mysql.connection.cursor()
cur.execute(f"""INSERT INTO site_info (`site_contact`, `contact_num`, `site_name`, `printer_count`, `terminal_count`, `cd_count`, `contract_status`, `special_notes`) values ("{addForm.contact.data}", "{addForm.contactnum.data}", "{addForm.sitename.data}", "{addForm.printercount.data}", "{addForm.termcount.data}", "{addForm.cdcount.data}", "{addForm.contractstatus.data}", "{specialnotes}"); """)
cur.connection.commit()
x = cur.execute('SELECT * FROM site_info')
data = cur.fetchall()
cur.close()
return render_template('add_site.html', title='Add site', data=data, form=form, addForm=addForm)
return render_template('add_site.html', title='Add Site', data=data, form = form, addForm=addForm)
答案 0 :(得分:1)
您的格式语法已关闭:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
应该是
...site_name="{{form.site.data}}";...