5/23/2020

Python - Full-Featured Web App Part 1 - Getting Started

** Full-Featured Web App Part 1 - Getting Started


==========================================

C:\Users\purunet>pip install flask
Collecting flask
  Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
     |████████████████████████████████| 94 kB 154 kB/s
Collecting Jinja2>=2.10.1
  Downloading Jinja2-2.11.2-py2.py3-none-any.whl (125 kB)
     |████████████████████████████████| 125 kB 656 kB/s
Collecting Werkzeug>=0.15
  Downloading Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB)
     |████████████████████████████████| 298 kB 2.2 MB/s
Collecting itsdangerous>=0.24
  Downloading itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB)
Collecting click>=5.1
  Downloading click-7.1.2-py2.py3-none-any.whl (82 kB)
     |████████████████████████████████| 82 kB 188 kB/s
Collecting MarkupSafe>=0.23
  Downloading MarkupSafe-1.1.1-cp38-cp38-win32.whl (16 kB)
Installing collected packages: MarkupSafe, Jinja2, Werkzeug, itsdangerous, click
, flask
Successfully installed Jinja2-2.11.2 MarkupSafe-1.1.1 Werkzeug-1.0.1 click-7.1.2
 flask-1.1.2 itsdangerous-1.1.0

==========================================

C:\Users\purunet>python
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>> exit()

==========================================

C:\Users\purunet\Documents\Flask_Blog>set FLASK_APP = flaskblog.py

==========================================

C:\Users\purunet\Documents\Flask_Blog>python flaskblog.py
 * Serving Flask app "flaskblog" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployme
nt.
   Use a production WSGI server instead.
 * Debug mode: on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 234-451-768
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [23/May/2020 12:48:56] " [37mGET / HTTP/1.1 [0m" 200 -
127.0.0.1 - - [23/May/2020 12:48:56] " [33mGET /favicon.ico HTTP/1.1 [0m" 404 -
 * Detected change in 'C:\\Users\\purunet\\Documents\\Flask_Blog\\flaskblog.py',
 reloading
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 234-451-768
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [23/May/2020 12:49:33] " [37mGET / HTTP/1.1 [0m" 200 -

==========================================

from flask import Flask

app = Flask(__name__)



@app.route('/')

def hello_world():

return 'Hello World!'



if __name__ == '__main__':

app.run()

---------------------------------





---------------------------------

==========================================

C:\Users\purunet\Documents\Flask_Blog>set FLASK_DEBUG=1

C:\Users\purunet\Documents\Flask_Blog>flask run
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployme
nt.
   Use a production WSGI server instead.
 * Debug mode: on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 556-684-567
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [23/May/2020 14:14:14] " [35m [1mGET / HTTP/1.1 [0m" 500 -
Traceback (most recent call last):
  File "C:\Users\purunet\AppData\Local\Programs\Python\Python38-32\Lib\site-pack
ages\flask\cli.py", line 338, in __call__
    self._flush_bg_loading_exception()
  File "C:\Users\purunet\AppData\Local\Programs\Python\Python38-32\Lib\site-pack
ages\flask\cli.py", line 326, in _flush_bg_loading_exception
    reraise(*exc_info)
  File "C:\Users\purunet\AppData\Local\Programs\Python\Python38-32\Lib\site-pack
ages\flask\_compat.py", line 39, in reraise
    raise value
  File "C:\Users\purunet\AppData\Local\Programs\Python\Python38-32\Lib\site-pack
ages\flask\cli.py", line 314, in _load_app
    self._load_unlocked()
  File "C:\Users\purunet\AppData\Local\Programs\Python\Python38-32\Lib\site-pack
ages\flask\cli.py", line 330, in _load_unlocked
    self._app = rv = self.loader()
  File "C:\Users\purunet\AppData\Local\Programs\Python\Python38-32\Lib\site-pack
ages\flask\cli.py", line 398, in load_app
    raise NoAppException(
flask.cli.NoAppException: Could not locate a Flask application. You did not prov
ide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was
 not found in the current directory.
127.0.0.1 - - [23/May/2020 14:14:14] " [37mGET /?__debugger__=yes&cmd=resource&f
=style.css HTTP/1.1 [0m" 200 -
127.0.0.1 - - [23/May/2020 14:14:14] " [37mGET /?__debugger__=yes&cmd=resource&f
=debugger.js HTTP/1.1 [0m" 200 -
127.0.0.1 - - [23/May/2020 14:14:16] " [37mGET /?__debugger__=yes&cmd=resource&f
=jquery.js HTTP/1.1 [0m" 200 -
127.0.0.1 - - [23/May/2020 14:14:17] " [37mGET /?__debugger__=yes&cmd=resource&f
=console.png HTTP/1.1 [0m" 200 -
127.0.0.1 - - [23/May/2020 14:14:18] " [37mGET /?__debugger__=yes&cmd=resource&f
=ubuntu.ttf HTTP/1.1 [0m" 200 -
127.0.0.1 - - [23/May/2020 14:14:18] " [37mGET /?__debugger__=yes&cmd=resource&f
=console.png HTTP/1.1 [0m" 200 -

---------------------------------





---------------------------------

==========================================

from flask import Flask
app = Flask(__name__)


@app.route("/")
def hello():
return "

Hello World!

"


if __name__ == '__main__':
app.run(debug=True)

---------------------------------





---------------------------------

==========================================

from flask import Flask
app = Flask(__name__)


@app.route("/")
@app.route("/home")
def home():
    return "

Home Page

"


@app.route("/about")
def about():
    return "

About Page

"


if __name__ == '__main__':
    app.run(debug=True)

---------------------------------