【发布时间】:2021-12-01 06:27:32
【问题描述】:
帮助我在这里被困了将近 3 天,现在我发布我的疑问 我的代码显示 405 错误
@app.route("/category/add")
def add_category():
form = AddCategory()
if form.validate_on_submit():
new_category = Categories(
title=form.name.data,
description=form.description.data,
review=form.review.data,
img_url=form.img_url.data,
)
db.session.add(new_category)
db.session.commit()
return render_template("index.html")
return render_template("add_category.html", form=form)
class AddCategory(FlaskForm):
name = StringField(label='Category name', validators=[DataRequired()])
description = StringField(label='Description', validators=[DataRequired()])
review = StringField(label='Review', validators=[DataRequired()])
img_url = StringField(label='Image Url ', validators=[DataRequired(), URL()])
submit = SubmitField(label='Add')
在条件语句之前运行完美
{% extends 'bootstrap/base.html' %}
{% import 'bootstrap/wtf.html' as wtf%}
{% block styles %}
{{ super() }}
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Nunito+Sans:300,400,700">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins:300,400,700">
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
{% endblock %}
{% block title %}Add Category{% endblock %}
{% block content %}
<div class="content">
<h1 class="heading">Add a Category</h1>
{{wtf.quick_form(form, novalidate=True)}}
</div>
{% endblock %}
add_category.html
【问题讨论】:
-
控制台有错误吗?表单数据很可能作为 POST 请求发送 - @app.route("/category/add",methods = ['GET','POST']) 允许这样做,405 指示方法不允许,默认值isvGET。
标签: python flask flask-wtforms http-status-code-405