Package: django-powerpages
Developer-friendly, simple CMS for Django, “flatpages on steroids”.Featuresedit pages in Admin using syntax highlighting - HTML, CSS, JavaScript, Django template languageedit pages as files using your favourite text editor or IDEon demand synchronization of pages between database and file system using Django commandsintegration with Django’s template systemattach custom server-side logic to a page through configurablePage Processorssitemap.xmlInstallationInstall package using pip:pipinstalldjango-powerpagesAdd'powerpages'toINSTALLED_APPSin your settings module:INSTALLED_APPS=(...'powerpages',)DefinePOWER_PAGESsetting: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')),]Addpowerpages.loader.WebsiteLoaderat end of yourloadersinTEMPLATES->OPTIONSsetting:TEMPLATES=[{...'OPTIONS':{...'loaders':['django.template.loaders.filesystem.Loader','django.template.loaders.app_directories.Loader',# Database template loader for powerpages app'powerpages.loader.WebsiteLoader',],...}...}]Run migrations:pythonmanage.pymigrateUsageAdmin screenshots:Edit pages using AdminAdmin interface allows to edit pages using the following fields:URL- unique address of every pageAlias- optional code name for page to be used to resolve it’s URL addressTitle,Description,Keywords- convenience fields to work with meta-tagsTemplate- page’s content as a Django template sourcePage ProcessorandPage Processor Config- options to assign and customize server-side logicURL 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 pageparent template can be overwritten by providingbase templateoption to the page processor config{% load ... %}tag is not necessary:template tag libraries fromsettings.POWER_PAGES['TAG_LIBRARIES']are loaded automaticallyadditional libraries may be provided usingtag librariesin page processor configPage Processorfield allows to select a Python class responsible for processing requests for current page.
Page processor can be configured using YAML config inPage Processor Configfield.
Default value,powerpages.DefaultPageProcessorjust renders page content and returns the output as200 OKresponse.
Other predefined options are:powerpages.RedirectProcessor- creates301 Moved Permanentlyor302 Foundresponse depending on booleanpermanentparameter. Redirect location is provided by URL (parameterto url), view name (to name) or Page alias (to alias).powerpages.NotFoundProcessor- generates404 Not Foundresponse.Example configuration of default page processor:basetemplate:myapp/base.htmlcontextprocessors:-myapp.context_processors.contexttaglibraries:-myapp_tagsheaders:{x-magic-id:'42'}cache:300cacheforuser:truesitemap:falseTo define a custom page processor you may create a subclass ofDefaultPageProcessorinsidepage_processors.pyfile in your app:# myapp/page_processors.pyfrompowerpages.page_processorsimportDefaultPageProcessorfrompowerpages.page_processor_registryimportregisterclassMyPageProcessor(DefaultPageProcessor):defprocess_request(self,request,extra_context=None):"""Process a request and create HTTP Response."""# Put your custom view logic hereregister(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 usingEdit modebutton.
This mode works only if template tag{% current_page_info %}has been added to the template source.File-Database SynchronizationExport pages from database to file system is done bywebsite_dumpcommand.
All pages are saved as structure of files and directories insidesettings.POWER_PAGES['SYNC_DIRECTORY'].
Exported pages can be modified using text editor and later loaded again into the database.pythonmanage.pywebsite_dumpExample structure of output directory:_index_.pageabout-us/_index_.pageabout-us/contact.pagedownload.pagerobots.txtEach of dumped files has the following structure:{...pagefieldsasJSON}## TEMPLATE SOURCE: ##...templatecontent(plaintext)Import pages from directory into database is done usingwebsite_loadcommand.pythonmanage.pywebsite_loadBoth website commands accept a variety of options to tweak their behaviour.
For the full list of options, use--help.XML Sitemapsdjango-powerpagescomes with a system for defining XML Sitemaps (alternative todjango.contrib.sitemaps).
By default, all accessible pages are listed as URLs insitemap.xml.
To remove a page from the sitemap user may add the following option to page processor config:sitemap:falsesitemapoption may be used to modify page’s sitemap params:sitemap:{changefreq:'daily',priority:0.9}Default values forchangefreqandpriorityfor all URLs can be set usingsettings.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 ofSitemaporModelSitemapclass insidesitemap.pyfile in your app:# myapp/sitemap.pyfrompowerpagesimportsitemap_configfrommyapp.modelsimportMyModelclassMyModelSitemap(sitemap_config.ModelSitemap):"""Sitemap config for Storage Powered by Open-E document files"""queryset=MyModel.objects.all()classMyStaticSitemap(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)RequirementsPython: 2.7, 3.4, 3.5Django: 1.9, 1.10