Sending data from html to python flask server "GET / HTTP/1.1" 405 error
<p>very new to python/AJAX and have been piecing everything from examples on the internet/flask documentation and I've gotten so far. Basically what I am trying to do is send latitude and longitude coordinates on a click (from mapbox API) to flask, and have that data print to console (to prove it has successfully gone Flask so I can work with it later).</p>

<p>data I am trying to send is formatted as: </p>

<pre><code>LngLat {lng: 151.0164794921875, lat: -33.79572045486767}
</code></pre>

<p>HTML:</p>

<pre><code>&lt;button onclick=submit() type="button"&gt;POST&lt;/button&gt;

&lt;script&gt;    
map.on('click', function (e) { 
console.log(e.lngLat)
});

function submit() {
var myData = e.lngLat
$.post( "/", $( "myData" ).serialize() 
);
}
&lt;/script&gt;
</code></pre>

<p>PY:</p>

<pre><code>from flask import Flask
from flask import request
from flask import render_template

app = Flask(__name__)

@app.route('/', methods=['POST'])
def home():
return render_template('index.html')
print(request.form['myData'])

if __name__ == '__main__':
app.run(debug=True)
</code></pre>

<p>when I try to run from console to localhost:5000 I get the error</p>

<pre><code>127.0.0.1 - - [23/Sept/2016 23:21:15] "GET / HTTP/1.1" 405 - 
</code></pre>

<p>I'm sorry if this is a silly question but I'm stumped for now! Thank you for your input </p>

<p>In your route, allow <code>GET</code> method, otherwise the html wil never render.</p>

<pre><code>@app.route('/', methods=['POST', 'GET'])
</code></pre>

<p>To print lat/lng to the console, first check if the method is <code>POST</code>, then print it:</p>

<pre><code>if request.method == 'POST':
    print(request.form.get('lng'), request.form.get('lat'))
</code></pre>

<p>This is the resulting code for the route:</p>

<pre><code>@app.route('/', methods=['POST', 'GET'])
def home():
    if request.method == 'POST':
        print(request.form.get('lng'), request.form.get('lat'))
    return render_template('index.html')
</code></pre>

javascript python html ajax flask