Skip to main content

Serve static pages, markdown, and assets from templates/pages directories.

Project description

plain.pages

Serve static pages, markdown, and assets from templates/pages directories.

Overview

The plain.pages package automatically discovers and serves static pages from templates/pages directories in your app and installed packages. Pages can be HTML, Markdown, redirects, or static assets, with support for frontmatter variables and template rendering.

# app/templates/pages/about.md
---
title: About Us
---

# About Our Company

We build great software.

This creates a page at /about/ that renders the markdown content with the title "About Us".

Pages are discovered from:

  • {package}/templates/pages/ for each installed package
  • app/templates/pages/ in your main application

The file path determines the URL:

  • index.html or index.md/
  • about.html or about.md/about/
  • docs/getting-started.md/docs/getting-started/
  • styles.css/styles.css (served as static asset)

Page types

HTML pages

HTML files are rendered as templates with access to the standard template context:

<!-- app/templates/pages/features.html -->
---
title: Features
---

<h1>{{ page.title }}</h1>
<p>Current user: {{ request.user }}</p>

Markdown pages

Markdown files (.md) are automatically converted to HTML:

<!-- app/templates/pages/guide.md -->
---
title: User Guide
template_name: custom-page.html
---

# User Guide

This is **markdown** content with [links](/other-page/).

Redirect pages

Files with .redirect extension create redirects:

# app/templates/pages/old-url.redirect
---
url: /new-url/
temporary: false
---

Assets

Any file that isn't HTML, Markdown, or a redirect is served as a static asset:

app/templates/pages/
├── favicon.ico
├── robots.txt
├── images/
│   └── logo.png
└── docs/
    └── guide.pdf

These are served at their exact paths: /favicon.ico, /images/logo.png, etc.

Template pages

Files containing .template. in their name are skipped and not served as pages. Use these for shared template fragments:

app/templates/pages/
├── base.template.html  # Not served
└── index.html          # Served at /

Markdown URLs

Optionally serve raw markdown content alongside rendered HTML pages. When enabled, each markdown file gets two URLs:

# settings.py
PAGES_MARKDOWN_URLS = True

With this setting enabled:

  • /docs/guide/ → Rendered HTML page
  • /docs/guide.md → Raw markdown content (without frontmatter)

The raw markdown URLs serve the content with text/plain content type, making them useful for:

  • External markdown processors
  • API consumers needing markdown source
  • Documentation tools that need raw content

Note: This feature is disabled by default. Only enable it if you need to serve raw markdown content.

Linking to Markdown URLs

When markdown URLs are enabled, you can link to the raw markdown version from templates:

<!-- In your page template -->
<a href="{{ page.get_markdown_url() }}">View Source</a>
<a href="{{ page.get_markdown_url() }}">Download Markdown</a>

The get_markdown_url() method returns:

  • The markdown URL (e.g., /docs/guide.md) if the page is markdown and the feature is enabled
  • None if the page is not markdown or the feature is disabled

Frontmatter

Pages support YAML frontmatter for configuration:

---
title: Custom Title
template_name: my-template.html
render_plain: true
custom_var: value
---

Available frontmatter options:

  • title: Page title (defaults to filename)
  • template_name: Custom template to use
  • render_plain: Skip template rendering (for markdown)
  • url: Redirect URL (for .redirect files)
  • temporary: Redirect type (for .redirect files)
  • Any custom variables accessible via page.vars

Custom views

The package provides view classes you can extend:

from plain.pages.views import PageView

class CustomPageView(PageView):
    def get_template_context(self):
        context = super().get_template_context()
        context["extra_data"] = self.get_extra_data()
        return context

The main view classes are:

Installation

Install the plain.pages package from PyPI:

uv add plain.pages

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plain_pages-0.12.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plain_pages-0.12.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file plain_pages-0.12.0.tar.gz.

File metadata

  • Download URL: plain_pages-0.12.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.11

File hashes

Hashes for plain_pages-0.12.0.tar.gz
Algorithm Hash digest
SHA256 2610eeab43a84158d430aa13140c8fc1631ca7a6ea452164488b167fa0285e22
MD5 977d84d9b0344e9b55256c332843d093
BLAKE2b-256 dc0b4a17faeffcdd80264a438e2a9fe153f9cb7b07f3af4a1f932f67d3a32002

See more details on using hashes here.

File details

Details for the file plain_pages-0.12.0-py3-none-any.whl.

File metadata

File hashes

Hashes for plain_pages-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3aa3d606e2390b87f0022c5721fabafd16e689dd4dbdd52ae7f5f19f56fc34b0
MD5 240b565b655ad468fec14e4d07fa91e7
BLAKE2b-256 e052a2c2995954388479ed1a6a067ea6edee58b04bcd2c649531ba00c482bcc1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page