Code Monkey home page Code Monkey logo

Comments (7)

euri10 avatar euri10 commented on April 28, 2024 3

You may (or I may misunderstand what you want to do) be mixing response_model and query parameters

  • to return a list you should have a response_model in the route @app.put("/items/{item_id}", response_model=List[Item])
  • the items: List[Item] part means you want a list of items in the query passed in the put
  • the curly braces around items most likely cast items to a set (not sure about that)

from fastapi.

tiangolo avatar tiangolo commented on April 28, 2024 3

Awesome @DaviOtero ! 🎉


As always, thanks @euri10 ! 👏 🌮 🍰

from fastapi.

tiangolo avatar tiangolo commented on April 28, 2024

Awesome! I'm glad you're liking it.

You should be able to:

return items

or:

return {"items": items}

from fastapi.

DaviOtero avatar DaviOtero commented on April 28, 2024

return items

God... it's so simple, i feel bad for not thinking of it.

Thank you guys!

from fastapi.

zopefiend avatar zopefiend commented on April 28, 2024

Working through the tutorial ( https://fastapi.tiangolo.com/tutorial/ ), hit stumbling block on first try. The command reads:
uvicorn main:app --reload
Is there some environment requirements that are not mentioned? Because that returns:
" 'uvicorn' is not recognized as an internal or external command,
operable program or batch file."
OK, so yes, I'm on a Windows desktop, That's what the employer provides ...
With uvicorn, fastapi, pydantic, etc. in /Lib/site-packages, I'm thinking that this should be equvalent:
[python directory]>python -m uvicorn main.py:main --reload
which tries to start, then error:
Error loading ASGI app. Could not import module "main.py".
OK, how about:
[python directory]>python -m uvicorn uvicorn.main.py:main --reload
Error loading ASGI app. Could not import module "uvicorn.main.py".
No? Try this:
[python directory]>python -m uvicorn. main.py
Error loading ASGI app. Import string "main.py" must be in format ":"
Right, that's why I had it the other way .., Once again:
[python directory]>python -m uvicorn uvicorn:main.py --reload
Error loading ASGI app. Attribute "main.py" not found in module "uvicorn"
Really odd, I'm looking right at it, in file explorer ...
Anyhow, pretty much stopped at the first command in the tutorial, thanks for any hints.

BTW, this editor delates some characters ( such as uderscores, around main ), and even whole words, so I won't be surprised if you can't read this as I typed it.

from fastapi.

ruoshui-git avatar ruoshui-git commented on April 28, 2024

@zopefiend Maybe try python -m uvicorn main:main --reload
But make sure in you code, you did:

main = FastAPI()

If you did:

app = FastAPI()

you should run

python -m uvicorn main:app --reload

In main:main, the first main is the package name, or your file name in this case, and the second main is the var/obj name in the package.

If you installed them in a virtual environment, you should be able to do just unicorn main:main --reload.

from fastapi.

zopefiend avatar zopefiend commented on April 28, 2024

from fastapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.