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 packageapp/templates/pages/in your main application
The file path determines the URL:
index.htmlorindex.md→/about.htmlorabout.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 /
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 userender_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:
PageView: Renders HTML and Markdown pagesPageRedirectView: Handles redirectsPageAssetView: Serves static assets
Installation
Install the plain.pages package from PyPI:
uv add plain.pages
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file plain_pages-0.10.5.tar.gz.
File metadata
- Download URL: plain_pages-0.10.5.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23c3e3da72ddd147065a7b3578f61b6df5e625b6a0f7e74da17f67fbf31fcddb
|
|
| MD5 |
cbe18d5190cd35834effe10ba42b0d5f
|
|
| BLAKE2b-256 |
182efa817a51b516396c3b074b478c03f1e55066ee8a19e8cf2e2d008a24eb8b
|
File details
Details for the file plain_pages-0.10.5-py3-none-any.whl.
File metadata
- Download URL: plain_pages-0.10.5-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a456f7315c96544deb6856bb88e081f1e36894f5784fd7a0ba70c4ae7b238897
|
|
| MD5 |
8eb840182f140f58e2b58c62c616427b
|
|
| BLAKE2b-256 |
301124037510b6ceccb5b970064fb836ae3c2f1b6dd79a494d940d0b6ed84a76
|