/django-mobile-template

Simple app that dynamically changes the templates based on domain/subdomain.

Primary LanguagePythonApache License 2.0Apache-2.0

Django-mobile-template

https://travis-ci.org/linevich/django-mobile-template.svg?branch=master

Simple django app that dynamically change template_name of your view based on domain name (e.g example.com and m.example.com).

Useful in case if you already have third party service that redirects to the mobile version of your site.

Installation

pip install django-mobile-template
# OR
pip install git+https://github.com/linevich/django-mobile-template.git
INSTALLED_APPS = [
...
'mobile_template',
...
]

Usage

Please note: MobileTemplateView should be first parent class.

# views.py

from django.views.generic import TemplateView
from mobile_template.views import MobileTemplateView


class Home(MobileTemplateView, TemplateView):
    template_name = 'index.html'

Templates folder structure:

templates
├── base.html
├── index.html
└── mobile
    └── index.html

Configuration

  • MOBILE_TEMPLATES_PREFIX (Default: mobile/) — mobile templates subfolder.
  • MOBILE_DOMAIN_REGEX (Default: ^m.\.*.\.*.*') — regular expression to capture mobile domains. By default it captures all domains started with m.<domain_or_subdomain>.