Skip to main content

django-site-basics

A reusable app to add favicon.ico, robots.txt, SEO tricks and 404/500 error pages handling for your site.

Installation

Install “django-site-basics” using pip or easy_install:

pip install django-site-basics

Add “favicon” to your INSTALLED_APPS in settings.py:

INSTALLED_APPS = (
    ...
    'site_basics',
)

Add site_basics URL patterns and handlers (if you want to use them) to urls.py:

handler404 = 'site_basics.views.page_404'
handler500 = 'site_basics.views.page_500'

urlpatterns = patterns('',
    ...
    url(r'^', include('site_basics.urls')),
)

Replace Django’s LocaleMiddleware with UpdatedLocaleMiddleware in your MIDDLEWARE_CLASSES:

MIDDLEWARE_CLASSES = (
    ...
    #'django.middleware.locale.LocaleMiddleware', # disabled in favor of UpdatedLocaleMiddleware
    'site_basics.middleware.UpdatedLocaleMiddleware',
    ...
)

Usage

Favicon

Put favicon.ico into your STATIC_ROOT. and you good to go, /favicon.ico will automatically redirect to /static/favicon.ico if your STATIC_URL = ‘/static/’.

Otherwise you can set a custom path to your favicon using FAVICON_PATH setting. For example:

FAVICON_PATH = STATIC_URL + 'images/favicon.png'

Robots.txt

robots.txt will be working out-of-the-box but if you need to customize it put custom robots.txt file into your templates directory. If you need to change template location use ROBOTS_TEMPLATE setting (robots.txt by default). Example:

ROBOTS_TEMPLATE = 'myfolder/robots.txt'

UpdatedLocaleMiddleware

This is a fix of Django i18n_urlpatterns and SEO problem described in Yawd’s article.

It changes LocaleMiddleware i18n redirects from Temporary (302) to Permanent (301) which prevents search engines from indexing and ranking double links for the same page.

To activate it replace Django’s LocaleMiddleware with UpdatedLocaleMiddleware in your MIDDLEWARE_CLASSES:

MIDDLEWARE_CLASSES = (
    ...
    #'django.middleware.locale.LocaleMiddleware', # disabled in favor of UpdatedLocaleMiddleware
    'site_basics.middleware.UpdatedLocaleMiddleware',
    ...
)

Error pages

Error pages work out-of-the-box providing you fancy themes from Annanta and Robotik.

http://www.designersdigest.co/wp-content/uploads/2010/03/404-Error-Template.jpg http://mogoolab.com/wp-content/uploads/2011/10/robotik_1-450x260.png

In development you can test these views by opening /test_page_404/ and /test_page_500/.

Annanta is default but you can switch to Robotik using setting:

ERROR_PAGE_THEME = 'robotik' # default is 'annanta'

You can also set a color:

ERROR_PAGE_THEME_COLOR = 'blue'

Available colors:

  • blue

  • green

  • gray (Robotik only)

  • grey (Annanta only)

  • red (Annanta only)

  • brown (Annanta only)

And if you’re using Django CMS you can show links to your root pages by setting:

ERROR_PAGE_CMS_LINKS = True

More configuration options below…

Configuration

ROBOTS_TEMPLATE

Sets a template for robots.txt handler (‘robots.txt’ by default). Example:

ROBOTS_TEMPLATE = 'myforlder/myrobotstemplate.txt'

ERROR_PAGE_THEME

Sets a theme for error pages (‘annanta’ or ‘robotik’, ‘annanta’ by default). Example:

ERROR_PAGE_THEME = 'robotik'

ERROR_PAGE_THEME_COLOR

Sets a color for error pages theme (‘blue’ by default). Example:

ERROR_PAGE_THEME_COLOR = 'green'

ERROR_404_PAGE_TEMPLATE

404 template (‘%s/404.html’ % ERROR_PAGE_THEME by default). Example:

ERROR_404_PAGE_TEMPLATE = 'myforlder/404.html'

ERROR_500_PAGE_TEMPLATE

500 template (‘%s/500.html’ % ERROR_PAGE_THEME by default). Example:

ERROR_404_PAGE_TEMPLATE = 'myforlder/500.html'

ERROR_PAGE_LOGO_URL

Set it if you want to display your logo on the error pages (None by default). Example:

ERROR_PAGE_LOGO_URL = '%simages/logo.png' % settings.STATIC_URL

ERROR_PAGE_SEARCH_ACTION

Allows you to setup a search form on your error pages (None by default).

Additional settings:

  • ERROR_PAGE_SEARCH_METHOD (‘GET’ by default)

  • ERROR_PAGE_SEARCH_PARAM (‘q’ by default)

Example:

ERROR_PAGE_SEARCH_ACTION = '/search/'
ERROR_PAGE_SEARCH_METHOD = 'POST'
ERROR_PAGE_SEARCH_PARAM = 'query'

Running the Tests

You can run the tests with via:

python setup.py test

or:

python runtests.py

TODO

  • Add more templates

  • Add locales and translations

  • Google Analytics

  • Sitemaps support

Credits

Metadata

Release files for django-site-basics 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-site-basics 0.2.2
File Size Uploaded Provenance Actions
django-site-basics-0.2.2.tar.gz 640.8 kB Without provenance Details for django-site-basics-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-site-basics 0.2.2
File Interpreter ABI Platform Actions
django_site_basics-0.2.2-py2.7.egg Legacy Egg format - - Details for django_site_basics-0.2.2-py2.7.egg

Total release size: 1.4 MB

Release files / django-site-basics-0.2.2.tar.gz

Download URL django-site-basics-0.2.2.tar.gz
Size 640.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d13f9ed641806341709220ea84e52b5e24300525d39acb7f5743ea6307eac4d4
BLAKE2b-256 checksum
How to use checksums
f0560a082d291e4cd9e320e0a0df2a9230a20e1ca4bedd43de8beccdb1315c2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_site_basics-0.2.2-py2.7.egg

Download URL django_site_basics-0.2.2-py2.7.egg
Size 752.3 kB
Tags Egg
SHA-256 checksum
How to use checksums
85223bd8589a6eccafbec93a20af0a1740b9c4ccc32f4331b890f5daad8a6ca4
BLAKE2b-256 checksum
How to use checksums
cf0a7d99dc65c8d1c62ee226a72479d38c1d5662d516fbeacd62592115174f70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-site-basics 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page