Driver variable undefined

I am taking this training:
Sessions and Transactions | GraphAcademy (neo4j.com)

One problem seems to be that they have named a python script neo4j.py, which creates a circular import. So I changed it to neo.py.

But with that done, I am not sure if these examples are supposed to work? How much modification needs to be done?

Several times they ask you to use the a 'with driver', but this doesn't work because the method 'driver' isn't defined.

When I try to put the method in context by using 'with current_app.driver', I get this error (I have bolded the relevant portion):

(neoflix) C:\Users\smoody\PythonProject\app-python\api>python neo.py
Traceback (most recent call last):
File "C:\Users\smoody\PythonProject\app-python\api\neo.py", line 39, in
with current_app.driver.session(database="people") as session:
^^^^^^^^^^^^^^^^^^
File "C:\Users\smoody\PythonProject\neoflix\Lib\site-packages\werkzeug\local.py", line 316, in get
obj = instance._get_current_object()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\smoody\PythonProject\neoflix\Lib\site-packages\werkzeug\local.py", line 513, in _get_current_object
raise RuntimeError(unbound_message) from None
RuntimeError: Working outside of application context.

This typically means that you attempted to use functionality that needed
the current application. To solve this, set up an application context
with app.app_context(). See the documentation for more information.

I don't understand how to correct this. It appears to be a flask error.

The corrected code assigns Flask(name) to a variable,

"
app = Flask(name)
"

Then it uses this when it executes the defined functions at the end,

"
with app.app_context():
init_driver(uri, username, password)
run_query()
close_driver()
"

It also uses a method "app_context".

Here is the corrected code:

from flask import Flask, current_app

from neo4j import GraphDatabase

app = Flask(name)

uri = 'bolt://##.##.##.##:####'
username = 'neo4j'
password = 'password'

def init_driver(uri, username, password):
current_app.driver = GraphDatabase.driver(uri,auth=(username, password))

current_app.driver.verify_connectivity()

return current_app.driver

def close_driver():
if current_app.driver != None:
current_app.driver.close()
current_app.driver = None

    return current_app.driver

def run_query():
with current_app.driver.session() as session:
result = session.run(
"MATCH (p:Person {name: $name}) RETURN p",
name = "Tom Hanks")
for record in result:
print (record)

with app.app_context():
init_driver(uri, username, password)
run_query()
close_driver()