Flat pages based on template directory structure for django.
- via virtualenv - yup we highly recommend it!
pip install django-template-pages
- Install
template_pages
- In your main template directory create
template_pages
folder, it will be your root template_pages directory - Connect
urls.py
,
urlpatterns = [
url(ur'any-other', YourFancyClass.as_view()),
# all others urls above - template_pages.urls last one to try!
url(ur'', include('template_pages.urls')),
]
- Create pages adding properly named files and folders in your
template_pages
template direcory, eg:
- template_pages/ # available at:
-- index.html # http://localhost/
-- nice-huh.html # http://localhost/nice-huh/
-- nice/
--- huh.html # http://localhost/nice/huh/
--- index.html # http://localhost/nice/
- define
TEMPLATE_PAGES_CONTEXT_MODULE
eg.
TEMPLATE_PAGES_CONTEXT_MODULE = 'apps.core.template_pages_context'
- create functions returning context named tweaked template path in
TEMPLATE_PAGES_CONTEXT_MODULE
:
# context for http://localhost/ vel template_pages/index.html
def index(request)
return {'foo' : 'bar'}
# context for http://localhost/nice-huh/ vel template_pages/nice-huh.html
def nicehuh(request)
return {'foo' : 'bar'}
# context for http://localhost/nice/huh/ vel template_pages/nice/huh.html
def nice_huh(request)
return {'foo' : 'bar'}
# context for http://localhost/nice/ vel template_pages/nice/index.html
def nice(request)
return {'foo' : 'bar'}
So context function name is created by changing relative path to template and applying:
- all
-
are stripped - all
/
became_
- use different than
*.html
extension (eg.*.htm
) to keep base files intemplate_pages/
structure and avoid unwanted base'ed named pages eg./base/
- to run test just
cd tests/test_project
and run
./manage.py tests
- fill them in here
1.0.2
- support for django 1.9+ 1.0.1
- do not supress
TemplateDoesNotExists
errors while onDEBUG = True
- do not supress
TemplateDoesNotExists
errors if they are raised by other stuff (eg. {% include %} template tag)