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.
pip install django-mobile-template
# OR
pip install git+https://github.com/linevich/django-mobile-template.git
INSTALLED_APPS = [
...
'mobile_template',
...
]
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
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>.