Build an App in Python
In the previous lessons, we learned about Python Loops, functions, modules and libraries, Data Structures and OOP, Debugging, Testing and Regular expression, and web application in Python. In the next lesson, we will implement a Python application.
Initiating virtual env and installing packages
Let's create a directory for our blog project. After you have created your project directory, create virtual environment using the following commands:
Activate the virtual environment:
Now let's use
pip to install required modules and packages that we will be using in this project.
Creating the flask app
First, create a new Flask app, by creating a file in root of the project directory called
Define a route for the home page:
Define a route to handle requests for individual blog posts:
Create templates for the home page and individual blog posts, we can do this by creating a new directory in root of project called
templates. And then further create the two following
Modify the home route to display a list of blog post titles:
Adding markdown posts
Now before running the app, let's add few posts.
Create a directory called
posts and add some Markdown files with blog post content.
Let's add a
Now, let's run the app, type the following command:
And you should see the following output in the terminal:
Here is how it would look, I have 2 blog posts and have some gifs in my blog posts. Navigate to
127.0.0.0:5000 in a browser window:
If we click on the
hello blog post:
We have concluded the series of Python tutorials. The series is intended for beginners who are interested in learning Python for Cloud Computing or DevOps. However, I want to emphasize that you cannot become a Python expert in just a few days. It is a starting point to understand the basics of the language and some related concepts. Python is a large and ever-evolving language, so becoming an expert takes time and practice. I hope that with the knowledge you have learned above, you can easily conquer Python.