python本地服务器搭建,如何为我的python脚本创建本地网络服务器?

本文探讨了如何在Windows环境下为用户提供本地Python脚本执行的服务,重点比较了使用原生Python Web服务器作为服务与Apache CGI的优缺点,建议利用Python WSGI实现轻量级服务,以HTML+浏览器作为用户界面。
摘要由CSDN通过智能技术生成

I'm looking to use a local webserver to run a series of python scripts for the user. For various unavoidable reasons, the python script must run locally, not on a server. As a result, I'll be using HTML+browser as the UI, which I'm comfortable with, for the front end.

I've been looking, therefore, for a lightweight web server that can execute python scripts, sitting in the background on a machine, ideally as a Windows service. Security and extensibility are not high priorities as it's all running internally on a small network.

Should I run a native python webserver as a Windows service (in which case, how)? Or is it just as easy to install Apache onto the user's machine and run as CGI? Since this is all local, performance is not an issue either.

Or am I missing something obvious?

解决方案

Don't waste a lot of time creating Windows service.

Don't waste a lot of time on Windows Apache.

Just make a Python service that responds to HTTP requests.

Look at http://docs.python.org/library/wsgiref.html

Python offers a WSGI reference implementation that makes your server easy and standards-compliant.

"I'm trying to avoid making the user run python stuff from the command prompt."

I don't see how clicking a web page is any different from clicking desktop icons.

Starting a web server based on Python is relatively easy, once you have the web server. First, build the server. Later, you can make sure the server starts. Let's look at some ways.

Your user can't use a random browser to open your local page. They need a bookmark to launch "localhost:8000/myspecialserverinsteadofthedestop/" That bookmark can be a .BAT file that (1) runs the server, (2) runs firefox with the proper initial URL.

You can put the server in the user's start-this menu.

You can make your Python program a windows "service".

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值