首页 > 解决方案 > giving error the request url was not found on your server

问题描述

i am getting error 404 while running this The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. how do i need to run the server ? please help

from flask import Flask
from flask import render_template
from flask import request

app = Flask(__name__, template_folder="templates/")

app.route("/login", method=['POST', 'GET'])

def index():
    greeting = "Hello World"
    if request.method == "POST":
        name = request.form['name']
        greet = request.form['greet']
        greeting = f"{greet}, {name}"
        return render_template("index.html", greeting=greeting)
    else:`enter code here`
        return render_template("hello_form.html")

if __name__ == "__main__":
    app.run(debug=True)

标签: pythonflask

解决方案


你需要更换

app.route("/login", method=['POST', 'GET'])

经过

@app.route("/login", methods=['POST', 'GET'])

编辑:还有,methods


推荐阅读