Package: django-roughpages
An template based theflatpageslike app.
Not like django’s flatpages app, django-roughpages render a template file which
determined from the accessed URL.
It is quite combinient when you want to render simple static page.
You do not need to prepareurls.pyorviews.pyanymore for that kind
of simple static page.django-roughpages callroughpages.views.roughpageview with the accessed
URL when django raiseHttp404exception.
The view automatically find the corresponding template file fromroughpagesdirectory in one of your template directories.
Assume if the user accessedhttp://localhost/foo/bar/hoge/.
If there is no urls pattern patched with the URL, django-roughpages try to find
corresponding template file such astemplates/roughpages/foo/bar/hoge.html.
If django-roughpages find the corresponding template file, it will render the
template and return theHttpResponse, otherwise it re-raiseHttp404exception.You can complicatedly select the corresponding template file.
django-roughpages determine the filename with a backend system.
The default backend isroughpages.backends.AuthTemplateFilenameBackendand
it preferhoge.anonymous.htmlorhoge.authenticated.htmlthanhoge.htmldepends on the accessed user authentication state.
Thus you can simply prepare the page for authenticated user as<something>.authenticated.htmland for anonymous user as<something>.anonymous.html.
Note that the filename which contains'.'is not allowed thus user cannot
accesshoge.authenticated.htmlwith a url like/hoge.authenticatedto prevent unwilling file acccess.You can control the backend behavior with making a custom backend.
To make a custom backend, you need to inheritroughpages.backends.TemplateFilenameBackendBaseand overrideprepare_filenames(self, filename, request)method.
The method receive an original filename andHttpRequestinstance and
must return a filename list.
The django-roughpages then try to load template file from the beginning of
the list, thus the order of the appearance is the matter.Documentationhttp://django-roughpages.readthedocs.org/en/latest/InstallationUsepiplike:$ pip install django-roughpagesUsageConfigurationAddroughpagesto theINSTALLED_APPSin your settings
moduleINSTALLED_APPS=(# ...'roughpages',)Add our extra fallback middlewareDjango >= 1.10MIDDLEWARE=(# ...'roughpages.middleware.RoughpageFallbackMiddleware',)Django < 1.10MIDDLEWARE_CLASSES=(# ...'roughpages.middleware.RoughpageFallbackMiddleware',)Createroughpagesdirectory in one of your template directories
specified withsettings.TEMPLATE_DIRSQuick tutorialCreateroughpages/foo/bar/hoge.htmlas follow<html><body>This is Hoge</body></html>Run syncdb and Start development server withpython manage.py syncdb; python manage.py runserver 8000Accesshttp://localhost:8000/foo/bar/hoge/and you will see “This is Hoge”Createroughpages/foo/bar/piyo.anonymous.htmlas follow<html><body>This is Piyo Anonymous</body></html>Createroughpages/foo/bar/piyo.authenticated.htmlas follow<html><body>This is Piyo Authenticated</body></html>Accesshttp://localhost:8000/foo/bar/piyo/and you will see
“This is Piyo Anonymous”Accesshttp://localhost:8000/admin/and login as admin user.Accesshttp://localhost:8000/foo/bar/piyo/and you will see
“This is Piyo Authenticated”NoteAny dots (‘.’) in a last part of URL is replaced to underscore (‘_’) to prevent a security risk.
Seehttps://github.com/lambdalisue/django-roughpages/issues/3