【发布时间】:2020-07-21 12:42:34
【问题描述】:
我有一个用 fastapi 编写的应用程序,并使用 uvicorn 和 supervisor 部署在 ubuntu 服务器上。
命令uvicorn main:app --host 0.0.0.0 --port 8000 启动应用程序。
我可以访问该地址的应用程序
myserver_ip:8000
应用程序有一个显示 (GET) 的表单
http://myserver_ip:8000/file/
@router.get("/file/")
async def file_receive():
content = """
<body>
<form action = "http://0.0.0.0:8000/image/uploadfile/" enctype="multipart/form-data" method="post">
<input name="file" type="file" multiple>
<input type="submit">
</form>
</body>
"""
return HTMLResponse(content=content)
action 参数是http://0.0.0.0:8000/image/uploadfile/ 但是在表单重定向之后,我没有转到页面http://myserver_ip:8000/image/uploadfile/。
如果我设置action = http://localhost:8000/image/uploadfile/,结果相同
当然,如果我直接设置动作变量 = http://myserver_ip:8000/image/uploadfile/ 一切都会开始工作。但是没有办法在本地机器上运行这段代码。
如何正确设置重定向?
【问题讨论】:
标签: python-3.x fastapi uvicorn