为了账号安全,请及时绑定邮箱和手机立即绑定

使用python在Azure函数HttpResponse中传递变量

使用python在Azure函数HttpResponse中传递变量

慕哥9229398 2024-01-04 15:28:19
我正在使用Python。必须将 Azure 函数中的变量 (comName) 传递给返回 func.HttpResponse 。下面是我的代码。    comName= 'Xerox'    return func.HttpResponse(status_code=200,headers={'content-type':'text/html'},             body=                """<!DOCTYPE html>                <html>                <body>                    <h1>Hello , thanks for your response {name} </h1>                </body>                </html>                """                )这是有效的,并返回 h1 标签。您好,感谢您的回复{name}
查看完整描述

1 回答

?
喵喵时光机

TA贡献1846条经验 获得超7个赞

是的,当然可以。


看看下面的简单例子:


import logging


import azure.functions as func

import sys


def main(req: func.HttpRequest) -> func.HttpResponse:

    logging.info('Python HTTP trigger function processed a request.')

    name = 'Bowman'

    return func.HttpResponse(

            body = f"<!DOCTYPE html><html><body><h1>Hello , thanks for your response {name} </h1></body></html>",

            headers={'content-type':'text/html'},

            status_code=200

    )

使用 f-string 获取变量。


这是 python 3.7 的一个特性。以前的版本需要使用format()方法。这是官方文档:


https://docs.python.org/3.7/tutorial/inputoutput.html


我可以得到回复:

https://img1.sycdn.imooc.com/65965e49000134a705970082.jpg

查看完整回答
反对 回复 2024-01-04
  • 1 回答
  • 0 关注
  • 42 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信