小编Am4*_*eur的帖子

如何在 HTTP 响应中返回 HTML 文件(Azure-Functions)

我正在学习使用 azure-functions,我想知道如何在这段代码上返回 HTML 文件。(azure-functions 的初始 python 代码)

import logging

import azure.functions as func



def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(f"Hello {name}!")
    else:
        return func.HttpResponse(
            "Please pass a name on the query string or in the request body",
            status_code=400
        )
Run Code Online (Sandbox Code Playgroud)

我想要的是这样的:

return func.HttpResponse("\index.html")
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

html python http azure azure-functions

4
推荐指数
1
解决办法
8881
查看次数

标签 统计

azure ×1

azure-functions ×1

html ×1

http ×1

python ×1