Skip to main content

Django application for serving page templates from the file system

Project description

Django-fspages is a small application for serving django page templates from the filesystem or other compatible storage. It may be used as a replacement for django.contrib.flatpages, have i18n support, is decoupled from Django ORM.

Application provide a fspages.views.serve view, which does mapping between matched path string in URL and page in the storage.

Each template may be supplemented with a serialized metadata file which have a same name as the template plus the entension suffix. Metadata is loaded by calling metadata loader (JSON by default).

If internationalization is enabled in django settings, the view will at first look for the localized version of the template by prepending the path with locale name directory and fallback to default language if not translation is available.


For a django-powered website with dozens of semi-static web pages, usage of flatpages may not always be a convenient, as several problem would arise soon:

  • flatpages does not support i18n content. You can not by default provide a version of page both in English and Deutsch languages.

  • flatpage content is a static HTML code, you can use django template language there, access template context, etc. You can’t fill several template’s placeholders without creating own flatpage object.

  • there are two separate paths of customizing the site appearance by the editors - by modifying templates (served from the file system by default), then editing HTML content of FlatPage object (via django admin interface).

  • version control of the FlatPage objects require additional integration with tools like django-reversion

Django-fspages tries to solve this problems by utilizing django storage api for storing pages objects and render them as the templates. Site editors can edit pages as regular files with their favorite editors and version control systems.


Why not pre-render/serve static files?

Static site generators work fine for their tasks, django-fspages is for sites which need to have semi-static pages (i.e. content depends on request parameters such as client IP address).

Why not to use template loader?

Comparing with dumb template rendering, django-fspages support correct path mapping, HTML redirects, metadata processing, i18n, sitemaps.

Installation and usage

Add fspages to settings.INSTALLED_APPS

Add fspages.views.serve into your urlconf, example:

from import FileSystemStorage
from import FSPageStorage

fspages_storage = FSPageStorage(

i18n_storage = FSPageStorage(

urlpatterns = patterns('',
    url(r'^pages/(?P<path>.*)$', 'fspages.views.serve', {
        'storage': fspages_storage,
        }, 'fspages'),

urlpatterns += i18n_patterns('',
    url(r'^i18n_pages/(?P<path>.*)$', 'fspages.views.serve', {
        'storage': i18n_storage,
        }, 'i18n_fspages')

View options

serve view have two required parameters, and few optional parameters:

path (required)

Path string matched in urlpattern, which to be mapped to page template.

storage (required) instance

FSPageStorage constructor parameters

backend (required)

django storage object instance, usually FileSystemStorage. django-fspages automatically extends FileSystemStorage with additional required methods declared in For other storage classes, you would need to provide those mixins on your own.


When path points to the directory, view tries to open index_document instead. Default: index.html


File extension for metadata files. Default: .meta.json


Callable which reveive a string with metadata file contents and needs to return a python dictionary. Default: json loader


Default metadata values. Default fspages.views.METADATA_DEFAULTS

Metadata parameters

Each page may be supplied with a metadata file with additional configuration parameters:


HTTP status code to respond with. Default: 200


Django template context to use in addition to RequestContext. Default: empty dictionary.


Custom content type. Default: mimetypes guessed type.


Page file encoding. Default: utf-8.


Place an URL of a target page if you need to do HTTP redirect. Page file SHOULD be in place, it may be empty. Default: False

Project details

Release history Release notifications | RSS feed

This version


Download files

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

Source Distribution

django-fspages-0.2.tar.gz (9.9 kB view hashes)

Uploaded Source

Built Distribution

django-fspages-0.2.macosx-10.8-x86_64.exe (75.4 kB view hashes)

Uploaded Source

Supported by

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