GitHub Octocat
found a bug/improvement?
Saltar al contenido principal
10 min web development 22/02/2022

Medium Python Project: How to Make a Static Website with Pelican?

Learn how to create a static website using Pelican, an important Python library for generating static websites.

Hello world! My name is Francisco, fcoterroba on the Internet and today I’m bringing you a post about programming since it’s one of the main sections of the website and, probably, one of the ones my readers like the most.

In this case, we’re going to create a static website (don’t worry if you don’t know what that is right now, I’ll explain it later) using Pelican, an important Python library.

Before starting with this project, I warn you that its difficulty is medium, whether you consider yourself a Python expert or if you’ve just started, this project is for you. Even so, it probably wouldn’t hurt to review the Python category on the website first, where all the projects previously made with this language are collected.

Before we begin, although I’ll explain what it is later, I recommend you visit a post I uploaded more than a month ago, where I explain many of the most used computer terms in our daily lives. Since, in this post, you’ll see words that probably won’t sound familiar to you. 🤯 You can read the post here.

I also want to remind you that a few months ago I uploaded a video to my YouTube channel, very interesting, focused on home automation. Specifically, we connected, configured, and installed a smart light bulb 💡 with which you can change its color, turn it off, turn it on, and much more simply by using your mobile phone and/or voice assistants like Google, Alexa, etc. 👇🏻

Before we start, what is a static website?

A static website is a web page/site on the Internet that displays the same content for all users instead of editing that personalized content.

To give you an idea, ANY social network is a dynamic website since, according to your interests, cookies, etc., it shows you completely different content than another user.

On the other hand, static pages are often seen frequently as landing pages and/or blogs.

Now let’s begin!

1️⃣ FIRST STEP 1️⃣

The first thing we have to do is install the Python programming language.

On Linux, almost as a general rule, Python comes pre-installed, but if not, we must go to the official Python website with which we can easily install the programming language on our computer.

When it’s installed, we’ll simply verify it using python --version in the terminal

Python verification

2️⃣ SECOND STEP 2️⃣

We must install the Python library manager. Personally, I prefer the typical pip3, although you can use any other like Anaconda

3️⃣ THIRD STEP 3️⃣

Once we have our manager installed, we’re going to install the library that will help us create our static website.

pip3 install pelican

Pelican installation

4️⃣ FOURTH STEP 4️⃣

We’re going to create a directory where, temporarily, we’re going to host our website. We enter it and inside, we’re going to run the command:

pelican-quickstart

Then we’ll have to answer a series of questions that the installer will ask us and we’ll have everything we need to start.

Pelican quickstart

5️⃣ FIFTH STEP 5️⃣

What would static websites be without content? Well, that’s it, without having created any article previously, we can’t see the website created with Pelican, that’s why we’re going to create our first test article.

Pelican uses Markdown, a markup language similar to HTML but with a much simpler syntax.

Inside the content folder we’re going to create a markdown file. It doesn’t matter if you use a code editor, if you use the terminal, or whatever, but in Markdown and following this style:

Markdown file example

Once created and saved, we proceed to generate the website. First, we have to generate it using: (at the project root)

pelican content

And then, for testing NOT FINAL DEPLOY, we use the command:

pelican -l

On screen it will show us the link with the port that our website points to while we don’t cancel or close that window. By default it’s usually localhost:8000

Pelican local server

With this, we would already have our static website created, although, as a final tip, we’re going to explain how to replace this default Pelican theme with one we decide.

6️⃣ SIXTH STEP 6️⃣

The first thing we should do is search the Pelican themes list for the theme we like the most.

In my case, I’m going to use Attila, a typical ghost theme so popular lately due to the use of Notion. This is the link

To install our theme, we’re going to clone or download the zip of the latest release, then we’re going to unzip that theme and use the following command:

sudo pelican-themes -U <theme_name>

Pelican theme installation

We can confirm that the theme has been installed correctly with the command:

sudo pelican-themes -l

Then we’re going to edit the pelicanconf.py file and AT THE END of the file we’re going to add the FULL PATH of the theme.

THEME = ".local/lib/python3.9/site-packages/pelican/themes/attila-1.3"

🏁 End of post 🏁

The final result is a static website uploaded to GH Pages (you can see how to do it here) where I’m going to give my point of view and color in a RANKING of my favorite songs for this Eurovision 2022.

If you want to see it, click on the image!

Eurovision 2022

And that’s all for today. Thanks for reading until the end, I hope it was useful and you liked it. See you soon!

You can contribute financially via Paypal. Any amount is truly appreciated! 🙂

I also hope you have a great week and we’ll see each other here soon! Greetings and remember to follow me on social media like Twitter, Facebook, Instagram, GitHub and LinkedIn. 🤟🏻

Sources: techlandia.com, python.org, pypi.org, anaconda.com, pelican.com, pelicanthemes.com, github.com, geekyshacklebolt.wordpress.com