Create a todo list with Python Flask and Vue.js. Part 1

Zhunisali Shanabek
3 min readFeb 21, 2022
Photo by Emile Perron on Unsplash

If you are a bit familiar with Python and want to learn how to create a REST API, then this article is for you.
Let’s learn how to make a REST API in Python. To do this, you need to install several packages. pip will help us with this.
pip — is a package management system written in Python. With pip we can install and remove any package.
We will write many commands in the terminal. Open a terminal. To open a terminal in Linux, there is a key combination: ctrl + alt + t. Write the following command on the command line:

$ apt-get install python3-pip

The number 3 means we want to install pip for version 3 of Python. You can install pip for version 2 of Python, but let’s keep up with the times and use new technologies. You may need root access. Add sudo at the beginning of the line. sudo — from English. “super user do”. By writing sudo you tell the OS that you have root access.

Virtual environment

To develop any program in Python, it is recommended to use a virtual environment. Why is it needed?
Imagine that you have several projects saved on your computer and each project uses many third-party packages. The problem is that these packages may have different versions for each of your projects.
This problem is solved by Virtual environment. It creates an isolated environment for the project. This environment will run the program and install packages with specific versions.
It sounds like it’s his home, and the packages are furniture chosen to his liking.
To download the virtual environment, enter:

$ pip3 install virtualenv
$ sudo apt install virtualenv

Create a folder for the project. Call it whatever you like. I’ve called todolist.

$ mkdir todolist
$ cd todolist

The virtualenv command creates a virtual environment. You must enter the name in the command parameters. I named env.

$ virtualenv -p python3 venv

This command will create a directory called venv in the root folder. This directory contains all the files for activating the virtual environment.

After you have created an environment, you need to activate it.

$ source venv/bin/activate

On your terminal, the name of the environment should appear on the left.

Installing packages

First of all, let’s install Flask. It is a library for building web applications.

$ pip3 install flask

Writing a code

Create a file named app.py. The minimal code for creating a Flask server looks like this:

Run a server

$ python app.py
* Serving Flask app 'app' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

In new terminal tab run to check server work

$ curl localhost:5000

Expect the following message

{"hello": "world"}

Or open a browser and go to the URL localhost:5000 . You’ll see following message

Great, you’ve successfully run a Flask server. Now we will add more routers and logic to our server in the following stories.

--

--