不允许的方法 请求的 URL 不允许使用该方法.405错误 - IT屋-程序员软件开发技术分享社区
首页
前端开发
不允许的方法 请求的 URL 不允许使用该方法.405错误
不允许的方法 请求的 URL 不允许使用该方法.405错误
[英] Method Not Allowed The method is not allowed for the requested URL. 405 Error
本文介绍了不允许的方法 请求的 URL 不允许使用该方法.405错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是构建 API 的新手.我正在构建一个非常简单的 API:执行时,显示 API 的 HTML 页面将要求输入名称:Api 将仅返回:Hello {name}".我收到 405 错误.这是我的 App.py 和 HTML 页面代码:
from app import app从烧瓶导入render_template从烧瓶导入请求@app.route('/')定义家():返回你好,没有世界!"@app.route('/template',methods=['POST','GET'])定义模板():输出 = [request.form.values()]输出=输出[0]return render_template('home.html',prediction_text='Hello {}'.format(output))
和我的 home.html 的 HTML 代码:
!doctype html><html lang="en-us"><头><元字符集=utf-8"><meta http-equiv="x-ua-compatible";内容=即=边缘"><title>欢迎回家</title>头部><身体><div class="登录"><h1>输入您的姓名</h1><!-- 接收查询的主要输入--><form action="{{ url_for('template')}}"method="post"><输入类型=文本"名称=名称"占位符=名称"必需=必需"/><按钮类型=提交"class=btn btn-primary btn-block btn-large">Enter</button></表单><br><br>{{ 预测文本 }}
</html>
我曾就这个问题查看过其他几个 StackOverflow 论坛.GET"似乎有问题或POST"方法,但我似乎无法弄清楚是什么?也许你们中的一个人可以看到我没有看到的东西.我在 Docker 内部运行这个 API,所以app = Flask(name )"存储在别处,如果相关.
不允许的方法 - 该请求的 URL 不允许使用方法
Flask - POST - 方法是请求的 URL 不允许
https://www.reddit.com/r/flask/评论/a04aew/ask_flask_help_me_to_find_the_error_in_my_code/
解决方案
此问题现已解决.我改变了两件事:
来自 HTML:改变:
到
并从 Flask API 更改:
output = [request.form.values()]输出=输出[0]return render_template('home.html',prediction_text='Hello {}'.format(output))
到
output = request.args.values()return render_template('home.html',prediction_text="Hello {}?".format(list(output)[:]))
I am new to building API. I am building a very Simple API: When executed, The HTML page displaying API will ask to enter name: the Api will just return: "Hello {name}". I am getting 405 Error. Here is my code for App.py and HTML page:
from app import app
from flask import render_template
from flask import request
@app.route('/')
def home():
return "hello no world!"
@app.route('/template',methods=['POST','GET'])
def template():
output = [request.form.values()]
output = output[0]
return render_template('home.html',prediction_text='Hello {}'.format(output))
and my HTML code for home.html:
!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Welcome home</title>
</head>
<body>
<div class="login">
<h1>Enter your name</h1>
<!-- Main Input For Receiving Query-->
<form action="{{ url_for('template')}}"method="post">
<input type="text" name="name" placeholder="Name" required="required" />
<button type="submit" class="btn btn-primary btn-block btn-large">Enter</button>
</form>
<br>
<br>
{{ prediction_text }}
</div>
</body>
</html>
I have looked at several other StackOverflow forums with just this issue. It seems like there is something wrong with "GET" or "POST" method but I can not seem to figure out what? Maybe one of you could see something I did not. I am running this API Inside a Docker so "app = Flask(name )" are stored elsewhere , If that is relevant.
Method Not Allowed - The method is not allowed for the requested URL
Flask - POST - The method is not allowed for the requested URL
https://www.reddit.com/r/flask/comments/a04aew/ask_flask_help_me_to_find_the_error_in_my_code/
解决方案
This question is now resolved. I changed two things:
From HTML:
Changing:
<form action="{{ url_for('template')}}"method="post">
to
<form action="{{ url_for('template')}}"method="get">
And Changing from Flask API:
output = [request.form.values()]
output = output[0]
return render_template('home.html',prediction_text='Hello {}'.format(output))
to
output = request.args.values()
return render_template('home.html',prediction_text="Hello {}?".format(list(output)[:]))
这篇关于不允许的方法 请求的 URL 不允许使用该方法.405错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文