full-stack-fastapi-template icon indicating copy to clipboard operation
full-stack-fastapi-template copied to clipboard

How to Debug using vs code

Open fatheyabdelslam opened this issue 1 year ago • 3 comments

i'm using this repo for my next project, but i can't figure out a way for debugging in vs code or connect jupyter server with vs code, i want to be able to set breakpoints and watch call sack .. etc.

fatheyabdelslam avatar Mar 26 '23 04:03 fatheyabdelslam

To run a debugger dockerless do the following.

Create a new file

|-- backend
|   |-- app
|      |-- app
|      |-- alembic
|      |run.py           <--------- Create this file

run.py

import uvicorn

if __name__ == "__main__":
    uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)

Use default launch

        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true
        }

Let me know if works.

miguelvalente avatar Mar 27 '23 17:03 miguelvalente

But the environment variable cannot be obtained

MaxwellEdisons avatar Jul 18 '23 13:07 MaxwellEdisons

@MaxwellEdisons you could re-load them again with dotenv (which should already be present as it used by pydantic)

import uvicorn
from dotenv import load_dotenv

load_dotenv("../.env")

if __name__ == "__main__":
    uvicorn.run("app.main:app", host="0.0.0.0", port=8002, reload=True)

davidhuser avatar Jul 20 '23 09:07 davidhuser

Reload dotenv using load_dotenv and reload = True while calling run method

import uvicorn
from dotenv import load_dotenv

load_dotenv("./.env")

if __name__ == "__main__":
    uvicorn.run("app.main:app", host="yout_local_host", port=your_port_no, reload=True)

AkashKobal avatar Aug 05 '24 04:08 AkashKobal