如何正确传递表单参数中的服务器IP地址?
How do I pass the server ip address in the form parameter correctly?
我有一个用 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/
一切都开始工作。但是没有办法在本地机器上 运行 这段代码。
如何正确设置重定向?
为什么不用亲戚url?
我有一个用 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/
一切都开始工作。但是没有办法在本地机器上 运行 这段代码。
如何正确设置重定向?
为什么不用亲戚url?