{ "info": { "author": "David Thenon", "author_email": "dthenon@emencia.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Introduction\n============\n\nThis is a simple Django app to publish some pages directly from templates. \n\nYes, this is simply to use a ``django.views.generic.TemplateView`` but this app will help to manage many pages and with Django sitemaps support.\n\nInstall\n=======\n\nAdd it to your installed apps in the settings : ::\n\n INSTALLED_APPS = (\n ...\n 'staticpages',\n ...\n )\n\nUsage\n=====\n\nAll static page entries must defines three arguments :\n\n* The regex pattern to match for the URL;\n* The template path to use;\n* The url name, that must be unique;\n\nThe raw way\n-----------\n\nIn the settings : ::\n\n STATICPAGES = [\n ...\n (r'foo/$', \"foo/index.html\", 'foo-index'),\n (r'foo/part1/$', \"foo/part1.html\", 'foo-part1'),\n (r'foo/part2/$', \"foo/part2.html\", 'foo-part2'),\n ...\n ]\n\nThen in your ``urls.py`` : ::\n\n url(r'^staticpages/', include('staticpages.urls.include')),\n\nIf you want to publish them in your ``sitemap.xml`` with Django sitemaps, you will have to do something like this in your ``urls.py`` : ::\n\n from staticpages.sitemaps import StaticPageSitemapBase, StaticPageEntryTemplate\n\n class MypagesSitemap(StaticPageSitemapBase):\n page_entries = [\n StaticPageEntryTemplate(url_name='mypage-foo', template_name='foo.html'),\n ]\n\n # Enabled sitemaps\n sitemaps = {\n # For Prototypes\n 'mypages': MypagesSitemap,\n }\n\n urlpatterns += patterns('django.contrib.sitemaps.views',\n url(r'^sitemap\\.xml$', 'sitemap', {'sitemaps': sitemaps}),\n )\n\nThe semi-auto way\n-----------------\n\nThis method enables you to mount different static pages maps for your needs, opposite to the raw way you can use any setting name to store your page map. This is useful if you need to multiple separated page maps.\n\nIn the settings : ::\n\n FOO_STATICPAGES = (\n (r'foo/$', \"foo/index.html\", 'foo-index'),\n (r'foo/part1/$', \"foo/part1.html\", 'foo-part1'),\n (r'foo/part2/$', \"foo/part2.html\", 'foo-part2'),\n )\n\n BAR_STATICPAGES = (\n (r'bar/$', \"bar/index.html\", 'bar-index'),\n (r'bar/part1/$', \"bar/part1.html\", 'bar-part1'),\n (r'bar/part2/$', \"bar/part2.html\", 'bar-part2'),\n )\n\nThen in your ``urls.py`` : ::\n\n from django.conf import settings\n from staticpages.urls import loaders\n\n urlpatterns = patterns('', *loaders.mount_staticpages(*settings.FOO_STATICPAGES)) + urlpatterns\n if settings.DEBUG:\n urlpatterns = patterns('', *loaders.mount_staticpages(*settings.BAR_STATICPAGES)) + urlpatterns\n\nNote the usage of ``settings.DEBUG``, this is an example of the usage you can do of multiple separated page maps, the *bar* pages will not be published in production environnment but the *foo* pages will be.\n \nAlso for the ``sitemap.xml`` with Django sitemaps, you will have to do something like this in your ``urls.py`` : ::\n\n from django.conf import settings\n from staticpages.sitemaps import StaticPageSitemapAuto\n\n class FooSitemap(StaticPageSitemapAuto):\n pages_map = settings.FOO_STATICPAGES\n\n class BarSitemap(StaticPageSitemapAuto):\n pages_map = settings.BAR_STATICPAGES\n\n\n # Enabled sitemaps\n sitemaps = {\n 'foo': FooSitemap,\n 'bar': BarSitemap,\n }\n\n urlpatterns += patterns('django.contrib.sitemaps.views',\n url(r'^sitemap\\.xml$', 'sitemap', {'sitemaps': sitemaps}),\n ) + urlpatterns\n\nStatic page view\n----------------\n\nAlso note that each page will use the view ``staticpages.views.StaticPageView``. This is just a inherit from ``django.views.generic.TemplateView`` that will contains a variable ``page_map``. This variable contains the used pages map. You can use it in your templates like so : ::\n\n