An template based the flatpages like 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 prepare
views.py anymore for that kind
of simple static page.
roughpages.views.roughpage view with the accessed
URL when django raise
The view automatically find the corresponding template file from
directory in one of your template directories.
Assume if the user accessed http://localhost/foo/bar/hoge/.
If there is no urls pattern patched with the URL, django-roughpages try to find
corresponding template file such as
If django-roughpages find the corresponding template file, it will render the
template and return the
HttpResponse, otherwise it re-raise
You can complicatedly select the corresponding template file.
django-roughpages determine the filename with a backend system.
The default backend is
hoge.html depends on the accessed user authentication state.
Thus you can simply prepare the page for authenticated user as
<something>.authenticated.html and for anonymous user as
Note that the filename which contains
'.' is not allowed thus user cannot
hoge.authenticated.html with a url like
/hoge.authenticated to prevent unwilling file acccess.
You can control the backend behavior with making a custom backend.
To make a custom backend, you need to inherit
roughpages.backends.TemplateFilenameBackendBase and override
prepare_filenames(self, filename, request) method.
The method receive an original filename and
HttpRequest instance 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.
Use pip like:
$ pip install django-roughpages
INSTALLED_APPSin your settings module
INSTALLED_APPS = ( # ... 'roughpages', )
Add our extra fallback middleware
Django >= 1.10
MIDDLEWARE = ( # ... 'roughpages.middleware.RoughpageFallbackMiddleware', )
Django < 1.10
MIDDLEWARE_CLASSES = ( # ... 'roughpages.middleware.RoughpageFallbackMiddleware', )
roughpagesdirectory in one of your template directories specified with
<html> <body> This is Hoge </body> </html>
Run syncdb and Start development server with
python manage.py syncdb; python manage.py runserver 8000
Access http://localhost:8000/foo/bar/hoge/ and you will see "This is Hoge"
<html> <body> This is Piyo Anonymous </body> </html>
<html> <body> This is Piyo Authenticated </body> </html>
Access http://localhost:8000/foo/bar/piyo/ and you will see "This is Piyo Anonymous"
Access http://localhost:8000/admin/ and login as admin user.
Access http://localhost:8000/foo/bar/piyo/ and you will see "This is Piyo Authenticated"
Any dots ('.') in a last part of URL is replaced to underscore ('_') to prevent a security risk. See https://github.com/lambdalisue/django-roughpages/issues/3