Flask error : Method Not Allowed The method is not allowed for the requested URL
Flask error : Method Not Allowed The method is not allowed for the requested URL
我正在使用 Flask 制作电影推荐系统项目,当我点击登录时我添加了登录页面,它显示
不允许的方法 所请求的 URL 不允许该方法。
“每当我尝试将数据提交到我的 Flask 表单时,我都会收到以下错误:
Method Not Allowed The method is not allowed for the requested URL.
Relevant parts of my code are as follows:
when i click on login it shows error method Not allowed.
help regarding this solution.
"
#自动完成一些电影
def get_suggestions():
data = pd.read_csv("tmdb.csv")
return list(data["title"].str.capitalize())
app = Flask(__name__)
#主页
@app.route("/index", methods=["GET", "POST"])
def index():
NewMovies = []
with open("movieR.csv", "r") as csvfile:
readCSV = csv.reader(csvfile)
NewMovies.append(random.choice(list(readCSV)))
m_name = NewMovies[0][0]
m_name = m_name.title()
with open("movieR.csv", "a", newline="") as csv_file:
fieldnames = ["Movie"]
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
writer.writerow({"Movie": m_name})
result_final = get_recommendations(m_name)
names = []
dates = []
ratings = []
overview = []
types = []
mid = []
for i in range(len(result_final)):
names.append(result_final.iloc[i][0])
dates.append(result_final.iloc[i][1])
ratings.append(result_final.iloc[i][2])
overview.append(result_final.iloc[i][3])
types.append(result_final.iloc[i][4])
mid.append(result_final.iloc[i][5])
suggestions = get_suggestions()
return render_template(
"index.html",
suggestions=suggestions,
movie_type=types[5:],
movieid=mid,
movie_overview=overview,
movie_names=names,
movie_date=dates,
movie_ratings=ratings,
search_name=m_name,
)
#登录码
@app.route("/")
@app.route("/login", methods=["GET", "POST"])
def login():
if flask.request.method == "POST":
un = request.form["username"]
pwd = request.form["password"]
if un not in database:
return flask.render_template("login.html", info="Invalid User")
else:
if database[un] != pwd:
return flask.render_template("login.html", info="Invalid Password")
else:
return render_template("index.html")
return render_template("login.html")
if __name__ == "__main__":
app.run()
您没有在 @app.route("/")
中指定 methods
。
新代码:
@app.route("/", methods=["GET", "POST"])
@app.route("/login", methods=["GET", "POST"])
def login():
if flask.request.method == "POST":
un = request.form["username"]
pwd = request.form["password"]
if un not in database:
return flask.render_template("login.html", info="Invalid User")
else:
if database[un] != pwd:
return flask.render_template("login.html", info="Invalid Password")
else:
return render_template("index.html")
return render_template("login.html")
我正在使用 Flask 制作电影推荐系统项目,当我点击登录时我添加了登录页面,它显示 不允许的方法 所请求的 URL 不允许该方法。 “每当我尝试将数据提交到我的 Flask 表单时,我都会收到以下错误:
Method Not Allowed The method is not allowed for the requested URL.
Relevant parts of my code are as follows:
when i click on login it shows error method Not allowed.
help regarding this solution.
"
#自动完成一些电影
def get_suggestions():
data = pd.read_csv("tmdb.csv")
return list(data["title"].str.capitalize())
app = Flask(__name__)
#主页
@app.route("/index", methods=["GET", "POST"])
def index():
NewMovies = []
with open("movieR.csv", "r") as csvfile:
readCSV = csv.reader(csvfile)
NewMovies.append(random.choice(list(readCSV)))
m_name = NewMovies[0][0]
m_name = m_name.title()
with open("movieR.csv", "a", newline="") as csv_file:
fieldnames = ["Movie"]
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
writer.writerow({"Movie": m_name})
result_final = get_recommendations(m_name)
names = []
dates = []
ratings = []
overview = []
types = []
mid = []
for i in range(len(result_final)):
names.append(result_final.iloc[i][0])
dates.append(result_final.iloc[i][1])
ratings.append(result_final.iloc[i][2])
overview.append(result_final.iloc[i][3])
types.append(result_final.iloc[i][4])
mid.append(result_final.iloc[i][5])
suggestions = get_suggestions()
return render_template(
"index.html",
suggestions=suggestions,
movie_type=types[5:],
movieid=mid,
movie_overview=overview,
movie_names=names,
movie_date=dates,
movie_ratings=ratings,
search_name=m_name,
)
#登录码
@app.route("/")
@app.route("/login", methods=["GET", "POST"])
def login():
if flask.request.method == "POST":
un = request.form["username"]
pwd = request.form["password"]
if un not in database:
return flask.render_template("login.html", info="Invalid User")
else:
if database[un] != pwd:
return flask.render_template("login.html", info="Invalid Password")
else:
return render_template("index.html")
return render_template("login.html")
if __name__ == "__main__":
app.run()
您没有在 @app.route("/")
中指定 methods
。
新代码:
@app.route("/", methods=["GET", "POST"])
@app.route("/login", methods=["GET", "POST"])
def login():
if flask.request.method == "POST":
un = request.form["username"]
pwd = request.form["password"]
if un not in database:
return flask.render_template("login.html", info="Invalid User")
else:
if database[un] != pwd:
return flask.render_template("login.html", info="Invalid Password")
else:
return render_template("index.html")
return render_template("login.html")