Skip to main content

This is a simple Django app to publish some pages directly from templates

Project description

Introduction

This is a simple Django app to publish some pages directly from templates.

Yes, this is simply to use a django.views.generic.TemplateView but this app will help to manage many pages and with Django sitemaps support.

Install

Add it to your installed apps in the settings :

INSTALLED_APPS = (
    ...
    'staticpages',
    ...
)

Usage

The raw way

In the settings :

STATICPAGES = [
    ...
    (r'foo/$', "foo.html", 'foo-mypage'),
    ...
]

Then in your urls.py :

url(r'^staticpages/', include('staticpages.urls.include')),

And so your page mypage-foo will be published on /staticpages/foo/ using the foo.html template.

If you want to publish them in your sitemap.xml with Django sitemaps, you will have to do something like this in your urls.py :

from staticpages.sitemaps import StaticPageSitemapBase, StaticPageEntryTemplate

class MypagesSitemap(StaticPageSitemapBase):
    page_entries = [
        StaticPageEntryTemplate(url_name='mypage-foo', template_name='foo.html'),
    ]

# Enabled sitemaps
sitemaps = {
    # For Prototypes
    'mypages': MypagesSitemap,
}

urlpatterns += patterns('django.contrib.sitemaps.views',
    url(r'^sitemap\.xml$', 'sitemap', {'sitemaps': sitemaps}),
)

The semi-auto way

This 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.

In the settings :

FOO_STATICPAGES = (
    ...
    (r'foo/$', "foo.html", 'foo-mypage'),
    ...
)

BAR_STATICPAGES = (
    ...
    (r'bar/$', "bar.html", 'bar-mypage'),
    ...
)

Then in your urls.py :

from django.conf import settings
from staticpages.urls import loaders

urlpatterns = patterns('', *loaders.mount_staticpages(*settings.FOO_STATICPAGES)) + urlpatterns
urlpatterns = patterns('', *loaders.mount_staticpages(*settings.BAR_STATICPAGES)) + urlpatterns

So your page foo-mypage will be published on /foo/ and bar-mypage will be published on /bar/.

Also for the sitemap.xml with Django sitemaps, you will have to do something like this in your urls.py :

from django.conf import settings
from staticpages.sitemaps import StaticPageSitemapAuto

class FooSitemap(StaticPageSitemapAuto):
    pages_map = settings.FOO_STATICPAGES

class BarSitemap(StaticPageSitemapAuto):
    pages_map = settings.BAR_STATICPAGES


# Enabled sitemaps
sitemaps = {
    'foo': FooSitemap,
    'bar': BarSitemap,
}

urlpatterns += patterns('django.contrib.sitemaps.views',
    url(r'^sitemap\.xml$', 'sitemap', {'sitemaps': sitemaps}),
) + urlpatterns

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

emencia-django-staticpages-0.3.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file emencia-django-staticpages-0.3.tar.gz.

File metadata

File hashes

Hashes for emencia-django-staticpages-0.3.tar.gz
Algorithm Hash digest
SHA256 f2f3764d7829df1c7fa1678c0715cb137ae78860a94c1de0b306bed2379909f9
MD5 4230226a5b690c1e8c62a014978ac3bc
BLAKE2b-256 36af20be0001c8abd6553776deeefb6474168fc6ee30283206c53316e29fb621

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page