我刚开始在Web开发环境中使用Python(我以前只是用它来编写我在命令行上运行的脚本)。我希望通过AJAX从HTML页面发送一些输入参数,运行python脚本,然后将我的python脚本生成的JSON对象发送回网页。我试图让这个例子运行只是为了弄清楚它是如何工作的:
http://davidderiso.com/post/6168199987/using-python-and-jquery#disqus_thread
我从test.py收到此错误消息:
Failed to load resource: the server responded with a status of 501 (Unsupported method ('POST'))
我是否需要使用像烧瓶或瓶子这样的python脚本?对不起,当涉及到这个东西时,我总是新手!
谢谢!
答案 0 :(得分:0)
该教程应该向您展示如何在没有框架的情况下完成它,但它非常不完整。例如,它没有讨论如何首先访问HTML文件。如果你只是在浏览器中将其作为文件打开,你可能会遇到这样的错误:你需要它由Apache提供服务(正如他指出的那样是为OSX内置的) - http://localhost/my_html_file.html
可能工作。
答案 1 :(得分:0)
我认为你应该使用Tornado Web Server!使用Tornado,你可以将你的python代码与你的html代码一起使用。
像这样......
{% 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>