gpt4 book ai didi

python - 从 AWS Python lambda 函数返回 html 页面

转载 作者:太空宇宙 更新时间:2023-11-04 15:51:05 28 4
gpt4 key购买 nike

我目前有一个返回 JSON 对象的 Python lambda 函数。然而,我想知道是否有办法返回一个返回而不是 JSON 的 html 网页,而不是得到一个带有 JSON 数据的白屏?目前返回数据看起来像

 return {
'statusCode': 200,
'headers': {},
'body': json.dumps({

'HOW-TO: ': prompt,
'instanceId': instanceId,
'PUBLIC_IP_ADDRESS': publicIp,
'instanceRegion':Instance_region
})

但是很好奇是否有办法返回 HTML 页面?

最佳答案

是的,您可以,只需使用 AWS Python 定义正确的 header

"headers": {'Content-Type': 'text/html'}

如下例(请调整正确的Python标识)

def lambda_handler(事件,上下文):

import json

longinformation = '''
<h1 style="color: #5e9ca0;">You can edit <span style="color: #2b2301;">this demo</span> text!</h1>
<h2 style="color: #2e6c80;">How to send HTML with AWS lambda in Python:</h2>
<p>Paste your documents in the visual editor on the left or your HTML code in the source editor in the right. <br />Edit any of the two areas and see the other changing in real time.&nbsp;</p>
'''

return {
"statusCode": 200,
"headers": {'Content-Type': 'text/html'}, #it really works by Hector Duran!
"body": longinformation
}

关于python - 从 AWS Python lambda 函数返回 html 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50192350/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com