Flask выдает ошибку 400 Bad Request
Всем привет! Я заполняю таблицу tbl_employer, но у меня Flask выдает ошибку 400 Bad Request.
Я вроде все написал правильно. Вод код на Python:
import MySQLdb
import pymysql
from flask import Flask, render_template, request
from pymysql import cursors
AllLogin = []
app = Flask(__name__ , template_folder = 'templates')
db = pymysql.connect(host='127.0.0.1',user='root',password='12002-tnA',db='studentsworks',charset='utf8') #,user_unicode='True')
print("Connect OK")
cursor1 = db.cursor(cursors.DictCursor)
cur = db.cursor()
Query = " Select id from tbl_employer "
cur.execute(Query)
AllLogin = cur.fetchall()
print('записи таблицы {} \n'. format(AllLogin))
for h in range(0, len(AllLogin)):
print('Очередной логин {} \n'. format(AllLogin[h][0]))
@app.route('/input', methods = ['GET', 'POST'])
def get_data():
if request.method == 'POST':
ENTERPRISE = request.form['enterprise']
LASTNAME = request.form['lastname']
NAME = request.form['name']
PATRONYMIC = request.form['patronymic']
POST = request.form['post']
PHONE = request.form['phone']
EMAIL = request.form['email']
PROBLEMS = request.form['problems']
sql = """ INSERT INTO tbl_employer(enterprise, lastname, name, patronymic, post, phone, email, problems) VALUES (%s, %s, %s, %s, %s, %s, %s, %s) """
cur.execute (sql, (ENTERPRISE, LASTNAME, NAME, PATRONYMIC, POST, PHONE, EMAIL, PROBLEMS))
db.commit()
return render_template('tbl_employers_3.html'
if __name__ == '__main__':
app.run(debug = True, host = '127.0.0.1' )
И на HTML:
<!DOCTIPE html>
<html lang = "en">
<head>
<meta charset = "UTF-8">
<title> Flask My Form </title>
<body bgcolor="#FFFFE0">
</head>
<hr color="#8B0000" size="5">
<table align="center" border="0" width="50" height="30">
<h1 align="center"> <font color="#8B0000" face="Open Sans"> Sign Up</font></h1>
<tr>
<form align="center" method = "POST" action = "/input">
<lable> Введи Название Предприятия </lable><input type= "text" name = "enterprise"><br><br>
<lable> Введи Фамилию </lable><input type= "text" name = "lastname"><br><br>
<lable> Введи Имя </lable><input type= "text" name = "name"><br><br>
<lable> Введи Отчество </lable><input type= "text" name = "patronymic"><br><br>
<lable> Введи Должность </lable><input type= "text" name = "post"><br><br>
<lable> Введи Телефон </lable><input type= "text" name = "phone"><br><br>
<lable> Введи эл.почту </lable><input type= "text" name = "email"><br><br>
<lable> Введи Номер Проблемы </lable><input type= "text" name = "problems"><br><br>
<input type = "submit" value = "Sign Up"></font></td>
</form>
</tr>
</table>
Заранее спасибо,
