I'm running a server with Flask. Here's my views.py:
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")
The user_form.html contains the following 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>
The user_form.html and mypython.py files are under the same "templates" directory. However, I get the message, " Method Not Allowed.The method is not allowed for the requested URL".
Looking at similar questions asked on Stackoverflow, I made sure to include "GET" and "POST" for methods. Why then I still have this error?
As a test, "mypython.py" is the following:
def restaurant_choice(zipcode, cuisine):
print "zipcode:", zipcode
return "cuisine: ", cuisine
restaurant_choice(getzipcode, getcuisine)