Last modified: March 23, 2026

This article is written in: πŸ‡ΊπŸ‡Έ

Deploying Static Python Website on Netlify

Netlify allows you to easily deploy and manage static websites. A Python-based static site generator like Pelican, MkDocs, or Frozen-Flask produces HTML files that Netlify serves through its global CDN.

+-----------+      push       +------------+     build      +----------+
 |           | -------------> |            | ------------> |          |
 | Git Repo  |                | Netlify    |               | CDN Edge |
 | (GitHub,  |                | Build Env  |               | Nodes    |
 |  GitLab)  |                | (Python +  |               | (Global) |
 |           | <------------- | pip)       | <------------ |          |
 +-----------+   webhook      +------------+   deploy       +----------+
                                                                |
                                                                |
                                                          +-----+-----+
                                                          |  End Users |
                                                          +-----------+

Steps to Deploy

  1. Create a Git repository containing your static Python website code and a requirements.txt:
# requirements.txt
pelican==4.9.1
markdown==3.6
  1. Sign up at netlify.com if you don't have an account.

  2. Connect your repository by clicking "New site from Git" in the Netlify dashboard, choosing your Git provider, and selecting the repository.

  3. Configure build settings in the dashboard or, preferably, through a netlify.toml file at the root of your repo:

[build]
  command = "pip install -r requirements.txt && pelican content -s publishconf.py"
  publish = "output"

[build.environment]
  PYTHON_VERSION = "3.11"

Continuous Deployment

[context.production]
  command = "pelican content -s publishconf.py"

[context.branch-deploy]
  command = "pelican content -s pelicanconf.py"

Preview Deploys

Environment Variables

PELICAN_SITEURL    = https://example.com
ANALYTICS_ID       = UA-XXXXXXXX-X
import os
SITEURL = os.environ.get("PELICAN_SITEURL", "http://localhost:8000")
[context.production.environment]
  PELICAN_SITEURL = "https://example.com"

[context.deploy-preview.environment]
  PELICAN_SITEURL = "https://preview.example.com"

Rollback

npm install -g netlify-cli
netlify deploy --prod --dir=output

Monitoring and Troubleshooting

[[redirects]]
  from = "/old-path"
  to = "/new-path"
  status = 301

With these steps and configurations, you can deploy, preview, and manage a static Python website on Netlify with full continuous deployment support.