Report 6 on my Linux course - Some more Python Flask

March 10, 2020

Posted in:

This week there's some more Python flask with a more complicated application

This time around I built a simple CRUD application which was of course a TODO -application. I followed this amazing guide from youtube:

Compared to last times I've used flask I also used virtualenv which makes the development process little bit more simple with the ability to use a virtual environment in where a developer can install all the dependancies instead of doing it globally.

Installing virtualenv requires pip3 which is a python package manager.

sudo apt-get install python3-pip

Virtual env can be installed with the command pip3 install virtualenv and you can create a new environment in your project folder with the command virtualenv env, where env is simply the name of the environment.

Finally you can activate it from the project root with command: source env/bin/activate.

The final product running on localhost port 5000 looks like this:

Screenshot 2020-03-11 at 0.02.40.png

After this I needed to configure the apache2 and mod-wsgi to get it working with this project.

I actually managed to get this working before in the class, but now I ran into issues with getting the production version of this working.

I have included a lot of screenshots about this. I followed this guide, I did this on my virtualbox installation of Xubuntu.

I had apache2 properly installed and configured here and I also had a 'mikkowsgi' -user with proper permissions.

Screenshot 2020-03-11 at 0.44.51.png

Also as can be seen here all my permissions were definately in order.

Screenshot 2020-03-11 at 0.49.16.png

Checking the error log actually revealed the source of the issue.

Screenshot 2020-03-11 at 0.53.35.png

I didn't have my sqlalchemy dependency installed properly here.

I tried first installing it again with the command sudo pip3 install flask_sqlalchemy but It gave me the following error:

Screenshot 2020-03-11 at 0.54.31.png

A great thing about this particular error is that it gave me the solution for it. I needed to run the pip3 install -command with the -H flag on the sudo command.

After this I ran the command curl -s localhost | grept title and it actually seemed to working. It returned the title of my webpage and checking localhost:80 returned me the proper webapplication.

Return to blog