问题描述
我已经用 Flask 设计了一个 rest API,现在我想在 python 中创建一个简单的 Web 服务器来获取和发布数据.如何在python中创建Web服务器?我不想使用 curl 和 localserver 5000
I have designed a rest API with Flask now I want to create a simple web server in python to get and post data. How to create web server in python? I do not want to use curl and localserver 5000
推荐答案
For Linux打开终端并输入:
For LinuxOpen up a terminal and type:
$ cd /home/somedir
$ python -m SimpleHTTPServer
现在您的 http 服务器将在端口 8000
中启动.您将收到消息:
Now your http server will start in port 8000
. You will get the message:
Serving HTTP on 0.0.0.0 port 8000 ...
现在打开浏览器并输入以下地址:
Now open a browser and type the following address:
http://your_ip_address:8000
您也可以通过以下方式访问它:
You can also access it via:
http://127.0.0.1:8000
或
http://localhost:8000
另请注意:
如果目录有一个名为 index.html 的文件,该文件将作为初始文件.如果没有index.html,则列出目录下的文件.
如果您想更改使用的端口,请通过以下方式启动程序:
If you wish to change the port that's used start the program via:
$ python -m SimpleHTTPServer 8080
将端口号更改为您想要的任何内容.
change the port number to anything you want.
这篇关于如何在 python 中创建一个简单的 HTTP 网络服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!