Search code examples
python-3.xfastapiuvicorn

How do I pass the server ip address in the form parameter correctly?


I have an application written in fastapi and deployed on the ubuntu server using uvicorn and supervisor. The command uvicorn main:app --host 0.0.0.0 --port 8000 starts the application. And I have access to the application at the address

myserver_ip:8000

The application has a form that (GET) is displayed at

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)

The action parameter is http://0.0.0.0:8000/image/uploadfile/ but after the form redirect, I don't go to the page http://myserver_ip:8000/image/uploadfile/. The same result if I set action = http://localhost:8000/image/uploadfile/

of course, if I set the action variable directly = http://myserver_ip:8000/image/uploadfile/ all everything starts to work. But then there is no way to run this code on a local machine. How do I set redirect correctly?


Solution

  • Why dont you use a relative url?