【问题标题】:How do I pass the server ip address in the form parameter correctly?如何在表单参数中正确传递服务器 ip 地址?
【发布时间】: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


    【解决方案1】:

    为什么不使用相对网址?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-12
      • 1970-01-01
      • 2011-08-13
      • 2016-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多