Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Flask: Hello World with get

Instead of the generic route method we could use the more specific get method to map the path to the function.

from flask import Flask

app = Flask(__name__)

@app.get("/")
def main_page():
    return "Hello World!"

The tests are the same as earlier.

import hello

def test_app():
    web = hello.app.test_client()

    rv = web.get('/')
    assert rv.status == '200 OK'
    assert rv.data.decode('utf-8') == 'Hello World!'

    # You can also test it this way:
    assert rv.data == b'Hello World!'