How can I create an local webserver for my python scripts?

后端 未结 3 1943
我寻月下人不归
我寻月下人不归 2021-02-01 07:05

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

3条回答
  •  不思量自难忘°
    2021-02-01 07:12

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

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

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


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

    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.

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

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

提交回复
热议问题