Quickstart¶
This page gives a brief introduction to the baguette module. It assumes you have baguette installed, if you don’t check the Installing portion.
Minimal website¶
Let’s see how a very simple app that returns a small HTML response looks.
1 2 3 4 5 6 7 | from baguette import Baguette
app = Baguette()
@app.route("/")
async def hello_world():
return "<h1>Hello world</h1>"
|
Just save it as hello-world.py
or something similar. Make sure to not call
your file baguette.py
because this would conflict with Baguette itself.
Make sure to have an ASGI server installed. Then simply run the server via:
uvicorn hello-world:app
You can also add the following code to the end of your program:
9 10 | if __name__ == "__main__":
app.run()
|
This will run your app on http://127.0.0.1:8000 by default, you can change the
host and the port with app.run(host="1.2.3.4", port=1234)
if you want to
run it on http://1.2.3.4:1234
. For more options, see
app.run
.