2
我正在用瓶的服务器。这里是我的views.py:电话:不允许的方法错误405
from flask import render_template
from app import app
@app.route('/')
@app.route('/user_form.html', methods=["GET", "POST"])
def index():
return render_template("user_form.html")
的user_form.html包含以下JavaScript:
<SCRIPT>
function get_UserInputValues(form) {
var getzipcode = document.getElementById('user_zip').value;
var getcuisine = document.getElementById('cuisine').value;
var selection1 = $("#slider1").slider("value");
var selection2 = $("#slider2").slider("value");
var selection3 = $("#slider3").slider("value");
var myurl = 'http://127.0.0.1:5000/mypython.py';
/*alert(getzipcode);
alert(getcuisine);
alert(selection1);
alert(selection2);
alert(selection3);*/
$('#myForm').submit();
$.ajax({url: myurl, type: "POST", data: {zip: getzipcode, cuisine:getcuisine}, dataType: 'json', done: onComplete})
}
function onComplete(data) {
alert(data);
};
</SCRIPT>
的user_form.html和mypython.py文件是相同的 “模板” 目录下。但是,我收到了消息“方法不允许,请求的URL不允许使用该方法”。
看着问#2类似的问题,我就确定包括“GET”和“POST”的方法。为什么我仍然有这个错误?
作为测试, “mypython.py” 如下:
def restaurant_choice(zipcode, cuisine):
print "zipcode:", zipcode
return "cuisine: ", cuisine
restaurant_choice(getzipcode, getcuisine)
什么是mypython.py? –
检查动词到达服务器的日志。它真的是一个POST吗?有时客户端发送OPTIONS然后GET/POST。 – Javier
这是我得到的日志中的终端:127.0.0.1 - - [29月/ 6/2014 19时二十分41秒] “POST/HTTP/1.1” 405 - – Rohit