mar5us
Student - Technical Writing
Unit C Lesson C2
Screen 1 of 11
1) Installing Python
2) Creating a virtual environment
3) Installing Flask
4) Configuring Flask
5) Building your first local Flask app
6) Running your first Flask app
7) Understanding web servers
8) Deploying to PythonAnywhere
Unit C Lesson C2
Screen 2 of 11
This lesson prepares you to:
Unit C Lesson C2
Screen 3 of 11
Remember the code you have written in Lesson C1:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run()
Unit C Lesson C2
Screen 4 of 11
Unit C Lesson C2
Screen 5 of 11
Python is an interpreted language: When running a Python script or application, the interpreter converts the Python program into something that the computer can understand.
In Windows, the path of the Python program must be passed to the interpreter as an argument. Example:
C:\Python32\python.exe C:\pathto\myPythonApp.py
Change to folder c:\~\myproject\app
Run "python ./app.py":
Note the message *Running on http://127.0.0.1:5000/.
This message refers to the Flask built-in web server which is running on port 5000 by default.
(venv) C:\~\myproject\app>python ./app.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Unit C Lesson C2
Screen 6 of 11
You will learn more about web servers in general during the next lesson, but here are some important notes about the Flask built-in web server:
Unit C Lesson C2
Screen 7 of 11
Open a web browser and connect to http://127.0.0.1:5000/ (or http://localhost:5000/)
Observe the "Hello World!" message inside the browser window.
Unit C Lesson C2
Screen 8 of 11
Note that you can open your venv again by running "activate.bat"
(venv) C:\~\myproject\app>python ./app.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [00/Mar/2000 00:00:00] "GET / HTTP/1.1" 200 -
(venv) C:\~\myproject\app>deactivate
C:\~\myproject\app>
Unit C Lesson C2
Screen 9 of 11
Having completed Unit C Lesson C2 you should now successfully be able to:
Unit C Lesson C2
Screen 10 of 11
Please perform the following steps before you proceed to Unit D:
Refer to the previous slides if necessary. Complete the assignment C2 once you are finished with above steps.
Unit C Lesson C2
Screen 11 of 11
By mar5us