[英]The method is not allowed for the requested URL - Flask + HTML
I am getting the message "The method is not allowed for the requested URL" on my html page. 我在html页面上收到消息“请求的URL不允许使用该方法”。 I know the problem is with POST method but can't find that out.
我知道问题出在POST方法上,但找不到。
My program is to list out the entries in one session. 我的程序是在一个会话中列出条目。
PYTHON: 蟒蛇:
from flask import Flask, render_template, request, session
from flask_session import Session
app = Flask(__name__)
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)
notes = []
@app.route("/", methods=["GET","POST"])
def index():
if request.method == "POST":
note = request.form.get("note")
notes.append(note)
return render_template("index.html", notes=notes)
if __name__ == '__main__':
app.run(debug = True)
HTML: HTML:
{% extends "layout.html" %}
{% block heading %}
NOTES
{% endblock %}
{% block body %}
<ul>
{% for note in notes %}
<li>{{ note }}</li>
{% endfor %}
</ul>
<form action="{{ url_for('index') }}" method="post">
<input type="text" name="note" placeholder="Type Here">
<button>Add Note</button>
</form>
{% endblock %}
I want a list of entries but getting the error - The method is not allowed for the requested URL. 我需要条目列表,但收到错误-请求的URL不允许使用该方法。
添加类型=''提交''为我工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.