Slides and files by Nauman Ahmad except for the wireless example.

The slides are in the pdf file:
Introduction to Flask_ahmad_nauman

To install flask:

pip install flask

Each application is of the form

foo
with subfolders
foo/templates

Within foo there is an app.py file.

The basic idea (p. 6 of Nauman's slides)
is to put the way to get to routines as "decorators" just above
the routine.
The following says to invoke the function home based on a call
to the url without any arguments.

@app.route('/')
def home()
	return "Hello World"

To run:
python app.py
http://localhost:5000

The following says to invoke the get_panda function and pass in the
value after /panda/ as an argument:

@app.route('/panda/<name>')
def get_panda(name):
	return "Welcome " + name

The following uses a template file and permits a call without and with
a name argument.


@app.route('/hello/')
@app.route('/hello/<name>')
def hello(name=None):
	return render_template('hello.html', name=name)

hello.html looks liks python with special surrounding characters:

<!doctype html>
<title> Hello from Flask </title>
{% if name %}
  <h1> Hello {{name}} </h1>
{% else %}
  <h1> Please give your name </h1>
{% endif %}

sqlite can be used as well (see slide 13 and the demo folder).


=====
Directories:
hw1.d has the simplest hello world application

So, from flask.d directory
cd hw1.d
cd hello-world
python app.py
Then go to browser and type
http://localhost:5000

Should get back
Hello World

Now, again from flask.d directory
cd hw2.d
cd hello-world
python app.py
http://localhost:5000/hello/tommy

Should get back
Hello tommy

Now, again from flask.d directory
cd hw3.d
cd hello-world
python app.py

http://localhost:5000/hello/Ellen

Should get back in bold
Hello Ellen

http://localhost:5000/hello

Should get back in bold
Hello World!

Take a look at index.html in templates to see
how you got that bold stuff.

Now return to flask.d
The wireless_pubs  directory has an sqlite example.
init.py builds a simple database.
Explain how.
app.py answers queries based on the database.
Search for the string THIS IS WHAT YOU MODIFY
Explain how the query works.

cd wireless_pubs

follow the README

Now return to flask.d
The demo directory has another sqlite example.
schema.sql builds a simple database.
Explain how.
app.py answers queries based on the database.
Search for the string THIS IS WHAT YOU MODIFY
Explain how the query works.

cd demo

Initialize the database using:

sqlite3 demo.db < schema.sql

Run the database server with
python app.py
http://localhost:5000/
to get a submit form.

Take a look at 
templates/index.html for the initial display.

Then put Football into the form.

Take a look at 
templates/results.html for the response to this query. 
