Ошибка в браузере werkzeug.exceptions.BadRequestKeyError
Возникла ошибка в браузере werkzeug.exceptions.BadRequestKeyError werkzeug.exceptions.BadRequestKeyError: 400 Плохой запрос: браузер (или прокси) отправил запрос, который этот сервер не может понять. KeyError: 'текст'
мой код python
from flask import Flask, render_template, url_for, request, redirect
from datetime import datetime
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///blog.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
class Article(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable=False)
intro = db.Column(db.String(300), nullable=False)
text = db.Column(db.Text, nullable=False)
date = db.Column(db.DateTime, default=datetime.utcnow)
def __repr__(self):
return '<Article %r>' % self.id
@app.route('/')
def auto():
return render_template('auto.html')
@app.route('/posts')
def posts():
articles = Article.query.order_by(Article.date).all()
return render_template("posts.html", articles=articles)
@app.route('/create-article', methods=['POST', 'GET'])
def create():
if request.method == "POST":
title = request.form['title']
intro = request.form['intro']
text = request.form['text']
article = Article(title=title, intro=intro, text=text)
try:
db.session.add(article)
db.session.commit()
return redirect('/')
except:
return "При добавлении статьи произошла ошибка"
else:
return render_template('create-article.html')
@app.route('/index')
def index():
return render_template('index.html')
@app.route('/about')
def about():
return render_template('about.html')
if __name__ == '__main__':
app.run(debug=True)
код html
<!doctype html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<title>Добавление статьи</title>
</head>
<body>
<div>
<h1>Добавление статьи</h1>
<form method="post">
<input type="text" name="title" id="title" class="form-control" placeholder="Введите название" ><br>
<textarea name="intro" id="intro" class="form-control"></textarea><br>
<textarea name="intro" id="text" class="form-control"></textarea><br>
<input type="submit" class="btn btn-success" value="Отправить">
</form>
</div>
</body>
</html>