This is an app sort of like Django's contrib.flatpages, but without the database. It's got a Fallback Middleware that just serves static html documents from your filesystem.
MIT License
It's like flatpages, but with templates
This is like Django's built-in contrib.flatpages
app, but without the database.
It's just static html documents served from your filesystem.
I've been using the flatpages
app for a long time, but somewhere along the
line I started keeping my flatpage content (snippets of html) in the git repo
with the rest of my project. Any time I made a change to a flatpage, I'd edit
the file locally, commit the changes, then copy and paste the new content into
the relevant flatpage.
Why not just serve these from my templates directory?
That's what staticflatpages
does.
Install the latest release with pip:
pip install django-staticflatpages
The most recent version of this app targets Django 2.1+ and Python 3.6+. Download a previous release for older versions of Django.
You can run the test suite with python manage.py test staticflatpages
, and open an
Issue on Github
if you run into any problems.
staticflatpages
to your INSTALLED_APPS
.staticflatpages.middleware.StaticFlatpageFallbackMiddleware
to yourMIDDLEWARE
settings.staticflatpages
template directory. This should be aTEMPLATES
setting. Anybase.html
) will get served asFor example, assuming your project-level template directory is named "templates", then:
/about/
will render templates/staticflatpages/about.html
/about/team/
will render templates/staticflatpages/about/team.html
templates/staticflatpages/index.html
), and/
, it will get used as your index.This app also supports sitemaps for staticflatpages. To enable these, you'll
need to have django.contrib.sitemaps
listed in your INSTALLED_APPS
setting.
Then, set up a sitemap (e.g. in your Root URLconf):
from staticflatpages.sitemaps import StaticFlatpageSitemap
sitemaps = {
'staticflatpages': StaticFlatpageSitemap,
}
Don't forget to include your sitemaps urls as normal, e.g.:
path(
'sitemap-<section>.xml',
sitemaps_views.sitemap,
{'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap'
),
path(
'sitemap.xml',
sitemaps_views.index,
{'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap'
),
NOTE: The sitemaps
framework also requires the sites
framework so you'll
need that installed, and you'll also need to define a SITE_ID
.
If you use the sitemaps feature, you may also want to include the following settings:
STATICFLATPAGES_CHANGEFREQ
: Corresponds to the Sitemap.changefreq
never
).STATICFLATPAGES_PRIORITY
: Corresponds to the Sitemap.priority
This app could work with with django-dirtyedit, which allows you to edit files from the admin (if you're so inclined).
This code is distributed under the terms of the MIT license. See the
LICENSE
file.