I'm new to using Python in a web development environment (I've previously just used it to write scripts I run on the command line). I'm hoping to send some input parameter from an HTML page via AJAX, run a python script, and then send back to the webpage a JSON object generated by my python script. I'm trying to get this example running just to get a sense for how this works:
http://davidderiso.com/post/6168199987/using-python-and-jquery#disqus_thread
I'm getting this error message from test.py:
Failed to load resource: the server responded with a status of 501 (Unsupported method ('POST'))
Do I need to be running this python script with something like flask or bottle? Sorry, I'm a total newbie when it comes to this stuff!
Thanks!
That tutorial is supposed to be showing you how to do it without a framework, but it's quite incomplete. For example, it doesn't talk about how you should be accessing the HTML file in the first place. If you simply open it as a file in your browser, you'd probably get that error: you need it to be served by Apache (which as he does point out is built in for OSX) - http://localhost/my_html_file.html
might work.
I think you should use the Tornado Web Server ! Using Tornado you would be able to have your python code alongside your html code.
Something like this ...
{% code %}
import pandas as pd
header = 'Using Tornado'
data = pd.read_csv('country_data.csv')
....
{% end %}
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{{ header }}</title>
<style>
...
<body>
...
</html>