Developer-friendly, simple CMS for Django, "flatpages on steroids".
Project description
Developer-friendly, simple CMS for Django, “flatpages on steroids”.
Features
edit pages in Admin using syntax highlighting - HTML, CSS, JavaScript, Django template language
edit pages as files using your favourite text editor or IDE
on demand synchronization of pages between database and file system using Django commands
integration with Django’s template system
attach custom server-side logic to a page through configurable Page Processors
sitemap.xml
Installation
Install package using pip:
pip install django-powerpages
Add 'powerpages' to INSTALLED_APPS in your settings module:
INSTALLED_APPS = (
...
'powerpages',
)
Define POWER_PAGES setting:
POWER_PAGES = {
# absolute path to directory, where page files are located:
'SYNC_DIRECTORY': '/path/to/directory/'
}
Include app’s URLs at the end of your urlconf:
urlpatterns = [
...
url(r'', include('powerpages.urls', namespace='powerpages')),
]
Run migrations:
python manage.py migrate
Usage
Admin screenshots:
Edit pages using Admin
Admin interface allows to edit pages using the following fields:
URL - unique address of every page
Alias - optional code name for page to be used to resolve it’s URL address
Title, Description, Keywords - convenience fields to work with meta-tags
Template - page’s content as a Django template source
Page Processor and Page Processor Config - options to assign and customize server-side logic
URL addresses of pages can be reversed in templates by using {% page_url alias %}. This template tag can also reverse URLs of regular Django views.
Page templates work as regular Django’s templates with few modifications:
{% extends ... %} tag should not be used:
by default each template inherits from template of parent page
parent template can be overwritten by providing base template option to the page processor config
{% load ... %} tag is not necessary:
template tag libraries from settings.POWER_PAGES['TAG_LIBRARIES'] are loaded automatically
additional libraries may be provided using tag libraries in page processor config
Page Processor field allows to select a Python class responsible for processing requests for current page. Page processor can be configured using YAML config in Page Processor Config field. Default value, powerpages.DefaultPageProcessor just renders page content and returns the output as 200 OK response. Other predefined options are:
powerpages.RedirectProcessor - creates 301 Moved Permanently or 302 Found response depending on boolean permanent parameter. Redirect location is provided by URL (parameter to url), view name (to name) or Page alias (to alias).
powerpages.NotFoundProcessor - generates 404 Not Found response.
Example configuration of default page processor:
base template: myapp/base.html
context processors:
- myapp.context_processors.context
tag libraries:
- myapp_tags
headers: {x-magic-id: '42'}
cache: 300
cache for user: true
sitemap: false
To define a custom page processor you may create a subclass of DefaultPageProcessor inside page_processors.py file in your app:
# myapp/page_processors.py
from powerpages.page_processors import DefaultPageProcessor
from powerpages.page_processor_registry import register
class MyPageProcessor(DefaultPageProcessor):
def process_request(self, request, extra_context=None):
"""Process a request and create HTTP Response."""
# Put your custom view logic here
register(MyPageProcessor)
Browse website in “edit mode”
Button “Edit mode” in Admin allows to show information about current page while browsing the website. User enables “Edit mode” for current session in Admin using Edit mode button. This mode works only if template tag {% current_page_info %} has been added to the template source.
File-Database Synchronization
Export pages from database to file system is done by website_dump command. All pages are saved as structure of files and directories inside settings.POWER_PAGES['SYNC_DIRECTORY']. Exported pages can be modified using text editor and later loaded again into the database.
python manage.py website_dump
Example structure of output directory:
_index_.page
about-us/_index_.page
about-us/contact.page
download.page
robots.txt
Each of dumped files has the following structure:
{
... page fields as JSON
}
## TEMPLATE SOURCE: ##
... template content (plain text)
Import pages from directory into database is done using website_load command.
python manage.py website_load
Both website commands accept a variety of options to tweak their behaviour. For the full list of options, use --help.
XML Sitemaps
django-powerpages comes with a system for defining XML Sitemaps (alternative to django.contrib.sitemaps). By default, all accessible pages are listed as URLs in sitemap.xml. To remove a page from the sitemap user may add the following option to page processor config:
sitemap: false
sitemap option may be used to modify page’s sitemap params:
sitemap: {changefreq: 'daily', priority: 0.9}
Default values for changefreq and priority for all URLs can be set using settings.POWER_PAGES:
POWER_PAGES = {
# (...)
'SITEMAP_DEFAULT_CHANGEFREQ': 'weekly',
'SITEMAP_DEFAULT_PRIORITY': 0.7,
}
To add custom URLs from your app to the sitemap you may define and register a subclass of Sitemap or ModelSitemap class inside sitemap.py file in your app:
# myapp/sitemap.py
from powerpages import sitemap_config
from myapp.models import MyModel
class MyModelSitemap(sitemap_config.ModelSitemap):
"""Sitemap config for Storage Powered by Open-E document files"""
queryset = MyModel.objects.all()
class MyStaticSitemap(sitemap_config.Sitemap):
items = (
{'location': sitemap_config.NamedURL('myview')},
{'location': sitemap_config.NamedURL('myview2', param='value')}
)
sitemap_config.sitemaps.add(MyModelSitemap)
sitemap_config.sitemaps.add(MyStaticSitemap)
Requirements
Python: 2.7, 3.4, 3.5
Django: 1.9, 1.10
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
Built Distribution
Hashes for django_powerpages-0.0.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e7b4d391ed1f4b551c2ac956ce3ce157e82bbe7e2de599cd5cf2fc80509a26c |
|
MD5 | 382a2f51080fd0a214e5d9c52a99b5fd |
|
BLAKE2b-256 | 642c51da0264182fe2a6065a65c11e9a1352813ed70d0a191c88d4d17da8d596 |