Book Image

Django 1.0 Template Development

Book Image

Django 1.0 Template Development

Overview of this book

Table of Contents (17 chapters)
Django 1.0 Template Development
Credits
About the Author
About the Reviewers
Preface
Index

Serving different templates by domain name


An increasingly common need for web applications is to serve a set of alternative templates for mobile devices. A common way to serve this alternative view of your site is to use a different domain name, such as mobile.mydomain.com, m.mydomain.com or mydomain.mobi.

Django makes it very easy to serve a secondary domain name from the same base project. When you configure your web server to serve your Django site, you tell it what settings file to use, so you can create a second settings file in the same directory and give it a different value for the TEMPLATE_DIRS setting.

For example, your main site would point to mycompany/settings.py and have a TEMPLATE_DIRS setting like this:

TEMPLATE_DIRS = (
    '/projects/mycompany/templates/',
)

Your mobile site would point to mycompany/settings_mobile.py with a TEMPLATE_DIRS setting like this:

TEMPLATE_DIRS = (
    '/projects/mycompany/templates/mobile/',
)

This technique gets even better when you realize that...