Getting started with Flask in nbdev.
↓ make sure we can create the app with/without specifying config
assert not create_app().testing
assert create_app({"TESTING": True}).testing
↓ make requests against a test client to show that we can GET
the /hello
route with/without specifying a name
app = create_app({"TESTING": True})
client = app.test_client()
response = client.get("/hello/Pieter van de Heuvel, MSc")
assert response.data == b"Hello, Pieter van de Heuvel, MSc!"
response = client.get("/")
assert response.data == b"Hello, World!"
The next cell just says "run the app if we're running from the command line". We use IN_NOTEBOOK
to avoid running the app when we're in the notebook.
from nbdev.export import notebook2script
notebook2script('50_flask_app.ipynb')