python - SimpleHTTPServer 允许 ajax 请求执行 PY 文件?

标签 python ajax python-2.7

我打算为我正在开发的 Python 脚本/模块制作一个简单的 Web 界面。我想提交一份表格,该表格可以执行两个选项中的一个。修改配置json文件并运行python脚本,或者向python脚本提交表单并执行它。

简单地说,我知道在使用其他一些应用程序(例如 Apache)时,您需要对其进行配置,使其接受 .py 文件作为可执行文件。 SimpleHTTPServer 也是同样的情况吗?如果是这样,怎么办?

我正在查看:https://docs.python.org/2/library/simplehttpserver.html

我还在 https://docs.python.org/2/library/basehttpserver.html#BaseHTTPServer.BaseHTTPRequestHandler 查看 BaseHTTPServer尽管在配置过程中我没有发现任何问题

最佳答案

您可以启用SimpleHTTPServer的CGI(通用网关接口(interface)https://en.wikipedia.org/wiki/Common_Gateway_Interface),请参阅以下线程How to host python cgi script with `python -m SimpleHTTPServer 8000` or `python -m CGIHTTPServer 8000`?

这类似于让 Django 运行 ( https://en.wikipedia.org/wiki/Django_(web_framework) ) 。 Django 是在 WSGI 兼容的网络服务器(Apache,...)上使用 mod_wsgi 模块或 FastCGI 启用的。

关于python - SimpleHTTPServer 允许 ajax 请求执行 PY 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43188538/

相关文章:

javascript - 当用户未登录时防止 AJAX 调用

python - 如何从二维列表中选择一个随机元素

python-2.7 - Python xpath抓取有问题

python - 为什么pygame不显示我的文本?

python - 在 Python DataFrame 中拆分字符串

python - 在 CentOS 上使用 Python 脚本连接 MySQL

Python按索引从字符串中删除字符的最佳方法

python - 测试用户输入 - Python

javascript - 关闭弹出模式

javascript - 使用 .load() 附加 URL - 加载内容的 id 或文件名