What I Have Learned While Using Python Flask

Sam Chen
4 min readOct 9, 2020

Python has become a very popular programming language throughout the recent decades, one of the top programming language to learn in 2020 (Feel free to check out my previous blog about this topic). Recently I have taken upon myself to start learning Python and Flask. Flask is one of the lightweight framework for Python, it is basically like an add-on to the Python. Today we will take a look at the learning process and try to avoid some of the mistakes that I made while learning.

To begin the learning process, we need to install Python. (https://www.python.org/downloads/). While going through the downloading process for Python, what I realized is that there are different versions of Python, Python 2.7 and Python 3.9. So what is the difference, Python 2.7 is an older version that supports a lot of the older file structure for earlier python developers, while Python 3.9 is the newest and most updated version of python that most developers use nowadays. (Python 2.7 is no longer being in support, meaning they won’t update and maintain this version). For our beginner user guide, we would start using Python 3.9 along with VS Code as the IDE.

Once we installed Python and VS Code, we need to go to VS Code and the extensions, type in python, and the first option should pop up as Python extension from Microsoft, this is the extension that Microsoft offers to help us connect Python to VS Code. Once that is installed, we can see on the bottom left of the VS Code screen, there is a version that Python is connected to, which is 3.8.5 64-bits. If it says Python 2.7, we can simply click on it and change it to 3.8. We can also go to the VS Code settings, and add a line of code shown below, to directly set up where the python file will directly come from.

We can tell from above image, we can check our python version with python — version and our default version of Python is 2.7.16. This can be a big problem when are trying to use Python 3.8.5 and installing Flask. In order for us to install flask, we need to install pip. What is pip? Pip is a standard package management system that helps us install any packages in python such as flask. To install pip, we need to run this command curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py , once the files are downloaded, we can install pip using the following command python get-pip.py this command will install all the packages in get-pip.py file. Once pip is installed, we can now install flask with the command pip install flask . Once Flask is installed, we can simply check by using the command flask --version and we will find out what version flask is installed and what version of python is installed under. One side note whenever we are going to run a python file, we have to use the command python3 app.py . This will allow the file to be run with Python 3 version, not the default Python 2 version.

After installing flask, we can happily begin to code! First simple task using flask would be something like the code snippet above. Import flask and route it to default localhost `http://127.0.0.1:5000/` and return Hello, World! as a string.

I know there are a lot more to discover with Python and Flask, but for now, we are just starting to use VS Code and Python and play around with them! Thanks for reading and have a great day!

--

--

Sam Chen

Yesterday I was clever, so I wanted to change the world. Today I am wise, so I am changing myself.