c836441a75
Hello World example at the main Readme file (https://github.com/channelcat/sanic/blob/master/README.rst) is different, it returns json. Here is returned text. In the following examples, such as Routing (http://sanic.readthedocs.io/en/latest/sanic/routing.html) is again used json. Therefore I suggest to make examples the same, having json as output
776 B
776 B
Getting Started
Make sure you have both pip and at
least version 3.5 of Python before starting. Sanic uses the new async
/await
syntax, so earlier versions of python won't work.
- Install Sanic:
python3 -m pip install sanic
- Create a file called
main.py
with the following code:
from sanic import Sanic
from sanic.response import json
app = Sanic()
@app.route("/")
async def test(request):
return json({"hello": "world"})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)
- Run the server:
python3 main.py
- Open the address
http://0.0.0.0:8000
in your web browser. You should see the message Hello world!.
You now have a working Sanic server!