发送和显示带有HTTP头的HTML

2024-10-03 09:18:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习一些关于HTTP协议的知识,并试图用Python编写一个基本的WSGI应用程序。我安装了gunicornWSGI服务器,并获得了一个基本的“helloworld”来工作

但是,我仍然想知道如何在页面上显示实际的HTML。也就是说,如何在响应中包含HTML

例如:

def app(environ, start_response):
    """Simplest possible application object"""
    data = b'<html> Hello, World!\n </html>'
    status = '200 OK'
    response_headers = [
        ('Content-type','text/plain'),
        ('Content-Length', str(len(data)))
    ]
    start_response(status, response_headers)
    return iter([data])

Tags: 服务器应用程序http协议wsgidataresponsehtml