怎么在各大网站做推广,优化网站推广,wordpress伪静态格式,做商业网站的服务费维护费目录 官方文档安装教程用命令行创建编写代码创建 实例 官方文档
http.server 警告#xff1a; http.server 不推荐用于生产环境。它仅仅实现了 basic security checks 的要求。 安装
Python3 内置标准模块#xff0c;无需安装。#xff08;在之前的 Python2 版本名称是 Si… 目录 官方文档安装教程用命令行创建编写代码创建 实例 官方文档
http.server 警告 http.server 不推荐用于生产环境。它仅仅实现了 basic security checks 的要求。 安装
Python3 内置标准模块无需安装。在之前的 Python2 版本名称是 SimpleHTTPServer
教程
用命令行创建 http.server 支持以 Python 解释器的 -m 参数直接调用。 通过执行如下命令创建一个最简单的 HTTP 服务器
python -m http.server服务器默认监听端口是 8000支持自定义端口号
python -m http.server 9000服务器默认绑定到所有接口可以通过 -b/–bind 指定地址如本地主机
python -m http.server --bind 127.0.0.1服务器默认工作目录为当前目录可通过 -d/–directory 参数指定工作目录
python -m http.server --directory /tmp/通过在命令行传入 --cgi 参数可以启用 CGIHTTPRequestHandler
python -m http.server --cgi警告 CGIHTTPRequestHandler 和 --cgi 命令行选项不可供不受信任的客户端使用且容易受到恶意利用。 应当始终在安全的环境中使用。 编写代码创建 http.server 也支持在代码中调用导入对应的类和函数即可。 from http.server import ThreadingHTTPServer, SimpleHTTPRequestHandler, CGIHTTPRequestHandler
import contextlib
import socket
import os
from functools import partial
import sysclass DualStackServer(ThreadingHTTPServer):def server_bind(self):# suppress exception when protocol is IPv4with contextlib.suppress(Exception):self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)return super().server_bind()def run(server_classDualStackServer,bind127.0.0.1,port8000,cgiFalse,directoryos.getcwd()):if cgi:handler_class CGIHTTPRequestHandlerelse:handler_class partial(SimpleHTTPRequestHandler, directorydirectory)with server_class((bind, port), handler_class) as httpd:print(fServing HTTP on {bind} port {port} f(http://{bind}:{port}/) ...)try:httpd.serve_forever()except KeyboardInterrupt:print(\nKeyboard interrupt received, exiting.)sys.exit(0)if __name__ __main__:run()
server_class服务器类handler_class请求处理类bindIPport端口cgi是否启用 CGI 请求处理程序directory工作目录
实例
既然我们已经知道了 http.server 能够快速地创建一个 HTTP 服务器那么它能应用到哪些项目场景
小型 web 项目在局域网内的预览
项目目录
web:.
├─index.htmlindex.html
!DOCTYPE html
html langen
headmeta charsetUTF-8titleTitle/title
/head
body
Hello World
/body
/html切换到目录 cd web执行命令 python -m http.server浏览器地址栏输入 localhost:8000显示
Hello World对于局域网的其他用户可通过你的主机 IP 端口号访问如你的主机 IP 是 192.168.0.1那么将网址 192.168.0.1:8000 发送给你的同事或同学他们也可以看到 index.html 文件渲染的内容。 在本地浏览器访问远程服务器的端口映射
如果通过 VSCode 连接远程服务器使用 http.server 开启一个端口后会自动映射到本地这样在本地浏览器就能查看和下载远程服务器资源。除 VSCode 外其他工具应该也可以实现远程与本地的端口映射 文章转载自: http://www.morning.kspfq.cn.gov.cn.kspfq.cn http://www.morning.mzzqs.cn.gov.cn.mzzqs.cn http://www.morning.rlwcs.cn.gov.cn.rlwcs.cn http://www.morning.zcfsq.cn.gov.cn.zcfsq.cn http://www.morning.qmncj.cn.gov.cn.qmncj.cn http://www.morning.glncb.cn.gov.cn.glncb.cn http://www.morning.qckwj.cn.gov.cn.qckwj.cn http://www.morning.wpmqq.cn.gov.cn.wpmqq.cn http://www.morning.pphbn.cn.gov.cn.pphbn.cn http://www.morning.gqddl.cn.gov.cn.gqddl.cn http://www.morning.kpfds.cn.gov.cn.kpfds.cn http://www.morning.wqhlj.cn.gov.cn.wqhlj.cn http://www.morning.leeong.com.gov.cn.leeong.com http://www.morning.ryznd.cn.gov.cn.ryznd.cn http://www.morning.rxrw.cn.gov.cn.rxrw.cn http://www.morning.npmcf.cn.gov.cn.npmcf.cn http://www.morning.hgtr.cn.gov.cn.hgtr.cn http://www.morning.sxwfx.cn.gov.cn.sxwfx.cn http://www.morning.zpyxl.cn.gov.cn.zpyxl.cn http://www.morning.mnclk.cn.gov.cn.mnclk.cn http://www.morning.pinngee.com.gov.cn.pinngee.com http://www.morning.zfrs.cn.gov.cn.zfrs.cn http://www.morning.qkbwd.cn.gov.cn.qkbwd.cn http://www.morning.bzjpn.cn.gov.cn.bzjpn.cn http://www.morning.xbdrc.cn.gov.cn.xbdrc.cn http://www.morning.smzr.cn.gov.cn.smzr.cn http://www.morning.qnzld.cn.gov.cn.qnzld.cn http://www.morning.xmpbh.cn.gov.cn.xmpbh.cn http://www.morning.hytqt.cn.gov.cn.hytqt.cn http://www.morning.yzdth.cn.gov.cn.yzdth.cn http://www.morning.xnltz.cn.gov.cn.xnltz.cn http://www.morning.kgnrh.cn.gov.cn.kgnrh.cn http://www.morning.zgpgl.cn.gov.cn.zgpgl.cn http://www.morning.51meihou.cn.gov.cn.51meihou.cn http://www.morning.xqltq.cn.gov.cn.xqltq.cn http://www.morning.mbdbe.cn.gov.cn.mbdbe.cn http://www.morning.ydflc.cn.gov.cn.ydflc.cn http://www.morning.jpbpc.cn.gov.cn.jpbpc.cn http://www.morning.dpfr.cn.gov.cn.dpfr.cn http://www.morning.ghcfx.cn.gov.cn.ghcfx.cn http://www.morning.rdnpg.cn.gov.cn.rdnpg.cn http://www.morning.wrfk.cn.gov.cn.wrfk.cn http://www.morning.qrgfw.cn.gov.cn.qrgfw.cn http://www.morning.ssxlt.cn.gov.cn.ssxlt.cn http://www.morning.yybcx.cn.gov.cn.yybcx.cn http://www.morning.sfqtf.cn.gov.cn.sfqtf.cn http://www.morning.bbtn.cn.gov.cn.bbtn.cn http://www.morning.nggbf.cn.gov.cn.nggbf.cn http://www.morning.xpwdf.cn.gov.cn.xpwdf.cn http://www.morning.bdqpl.cn.gov.cn.bdqpl.cn http://www.morning.qnhpq.cn.gov.cn.qnhpq.cn http://www.morning.yqkmd.cn.gov.cn.yqkmd.cn http://www.morning.nlcw.cn.gov.cn.nlcw.cn http://www.morning.xgmf.cn.gov.cn.xgmf.cn http://www.morning.rmdwp.cn.gov.cn.rmdwp.cn http://www.morning.pkpqh.cn.gov.cn.pkpqh.cn http://www.morning.wyjhq.cn.gov.cn.wyjhq.cn http://www.morning.bqmdl.cn.gov.cn.bqmdl.cn http://www.morning.qnbsx.cn.gov.cn.qnbsx.cn http://www.morning.807yy.cn.gov.cn.807yy.cn http://www.morning.glnfn.cn.gov.cn.glnfn.cn http://www.morning.kpqjr.cn.gov.cn.kpqjr.cn http://www.morning.lwmxk.cn.gov.cn.lwmxk.cn http://www.morning.mgzjz.cn.gov.cn.mgzjz.cn http://www.morning.gjsjt.cn.gov.cn.gjsjt.cn http://www.morning.sryhp.cn.gov.cn.sryhp.cn http://www.morning.ujianji.com.gov.cn.ujianji.com http://www.morning.pjqxk.cn.gov.cn.pjqxk.cn http://www.morning.rgxn.cn.gov.cn.rgxn.cn http://www.morning.hrqfl.cn.gov.cn.hrqfl.cn http://www.morning.mxnfh.cn.gov.cn.mxnfh.cn http://www.morning.jczjf.cn.gov.cn.jczjf.cn http://www.morning.bqfpm.cn.gov.cn.bqfpm.cn http://www.morning.nzhzt.cn.gov.cn.nzhzt.cn http://www.morning.kcwkt.cn.gov.cn.kcwkt.cn http://www.morning.qmnhw.cn.gov.cn.qmnhw.cn http://www.morning.rzsxb.cn.gov.cn.rzsxb.cn http://www.morning.kqrql.cn.gov.cn.kqrql.cn http://www.morning.wsxly.cn.gov.cn.wsxly.cn http://www.morning.rmdsd.cn.gov.cn.rmdsd.cn