如何为我的python脚本创建本地网络服务器? [英] How can I create an local webserver for my python scripts?

查看:248
本文介绍了如何为我的python脚本创建本地网络服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找使用本地Web服务器为用户运行一系列python脚本的方法.由于各种不可避免的原因,python脚本必须在本地运行,而不是在服务器上运行.结果,我将使用HTML +浏览器作为前端使用的UI.

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.

因此,我一直在寻找一种可以执行python脚本的轻量级Web服务器,该服务器位于计算机的后台,理想情况下作为Windows服务.安全性和可扩展性不是全部要考虑的重点,因为它们都在小型网络内部运行.

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.

我应该将本机python网络服务器作为Windows服务运行(在这种情况下,如何)?还是将Apache安装到用户计算机上并像CGI一样容易地运行?由于这全部是本地的,因此性能也不是问题.

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?

推荐答案

不要浪费很多时间来创建Windows服务.

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

不要在Windows Apache上浪费很多时间.

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

只需创建一个响应HTTP请求的Python服务即可.

Just make a Python service that responds to HTTP requests.

查看 https://docs.python.org/2/library/basehttpserver .html
https://docs.python.org/3/library/http.server. html 用于版本3
Python提供了一个HTTP服务器,您可以使用服务器端方法对其进行扩展.

Look at https://docs.python.org/2/library/basehttpserver.html
https://docs.python.org/3/library/http.server.html for version 3
Python offers an HTTP server that you can extend with your server-side methods.

查看 http://docs.python.org/library/wsgiref.html
Python提供了WSGI参考实现,可简化您的服务器并使其符合标准.

Look at http://docs.python.org/library/wsgiref.html
Python offers a WSGI reference implementation that makes your server easy and standards-compliant.

http://fragments.turtlemeat.com/pythonwebserver.php

我正在尝试避免使用户从命令提示符下运行python内容."

"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.

在拥有Web服务器之后,启动基于Python的Web服务器相对容易.首先,构建服务器.稍后,您可以确保服务器启动.让我们看看一些方法.

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.

  1. 您的用户无法使用随机浏览器打开您的本地页面.他们需要一个书签来启动"localhost:8000/myspecialserver而不是thedestop/".该书签可以是一个.BAT文件,该文件(1)运行服务器,(2)使用正确的初始URL运行firefox.

  1. 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.

您可以使您的Python程序成为Windows的服务".

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

这篇关于如何为我的python脚本创建本地网络服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆