我正在使用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
我可以得到回復:
添加回答
舉報
0/150
提交
取消