假设我的Web应用程序在服务器端完全支持PUT和DELETE,我应该使用它们吗?
基本上我的问题是有多少浏览器支持这个:
<form method="PUT">
Run Code Online (Sandbox Code Playgroud)
要么
<form method="DELETE">
Run Code Online (Sandbox Code Playgroud)
除了兼容REST之外,使用这两种HTTP方法有什么好处吗?(假设替换这两种方法是常用的POST)
我刚刚开始学习Flask,我正在尝试创建一个允许POST方法的表单.这是我的方法:
@app.route('/template', methods=['GET', 'POST'])
def template():
if request.method == 'POST':
return("Hello")
return render_template('index.html')
Run Code Online (Sandbox Code Playgroud)
我的index.html:
<html>
<head>
<title> Title </title>
</head>
<body>
Enter Python to execute:
<form action="/" method="post">
<input type="text" name="expression" />
<input type="submit" value="Execute" />
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
加载表单(在收到GET时呈现它)工作正常.但是,当我单击提交按钮时,我收到POST 405错误方法不允许.为什么不显示你好?
尝试提交请求时出现此错误。
Method Not Allowed
The method is not allowed for the requested URL.
Run Code Online (Sandbox Code Playgroud)
这是我的烧瓶代码。
@app.route("/")
def hello():
return render_template("index.html")
@app.route("/", methods=['POST','GET'])
def get_form():
query = request.form["search"]
print query
Run Code Online (Sandbox Code Playgroud)
还有我的index.html
<body>
<div id="wrap">
<form action="/" autocomplete="on" method="POST">
<input id="search" name="search" type="text" placeholder="How are you feeling?">
<input id="search_submit" value="Send" type="submit">
</form>
</div>
<script src="js/index.js"></script>
</body>
Run Code Online (Sandbox Code Playgroud)
编辑..我完整的烧瓶代码:
from flask import Flask,request,session,redirect,render_template,url_for
import flask
print flask.__version__
app = Flask(__name__)
@app.route("/")
def entry():
return render_template("index.html")
@app.route("/data", methods=['POST'])
def entry_post():
query = request.form["search"]
print query
return …Run Code Online (Sandbox Code Playgroud)