Python 如何向http请求发送图像?
制作WSGI应用程序。Python 如何向http请求发送图像?,python,http,wsgi,Python,Http,Wsgi,制作WSGI应用程序。 当浏览器看到连接的文件时- <script src="static/js/func.js"></script> 我使用“打开”功能读取文件,并将结果放入“返回”中。 该浏览器还尝试获取“favicon.ico”等图像 GET net::ERR\u EMPTY\u响应 如何将图像返回到查询,使用什么 def giveFile(environ, start_response): headers = [('Content-Type', 'te
当浏览器看到连接的文件时-
<script src="static/js/func.js"></script>
我使用“打开”功能读取文件,并将结果放入“返回”中。该浏览器还尝试获取“favicon.ico”等图像 GET net::ERR\u EMPTY\u响应 如何将图像返回到查询,使用什么
def giveFile(environ, start_response):
headers = [('Content-Type', 'text/html')]
status = '404 NOT FOUND'
file = ''
if os.path.exists(environ['PATH_INFO'][1:]):
status = '200 OK'
with open(environ['PATH_INFO'][1:], encoding='utf-8') as res:
file = res.read()
if 'js' in environ['url_args']:
headers = [('Content-Type', 'application/javascript')]
elif 'css' in environ['url_args']:
headers = [('Content-Type', 'text/css')]
start_response(status, headers)
return [file.encode()]