基于域/子域动态更改模板的简单应用程序。
django-mobile-template的Python项目详细描述
简单的django应用程序,可以根据域名动态更改视图的template_name
(例如example.com和m.example.com)。
如果您已经有第三方服务重定向到您站点的移动版本,则此功能非常有用。
安装
pip install django-mobile-template
# OR
pip install git+https://github.com/linevich/django-mobile-template.git
INSTALLED_APPS=[...'mobile_template',...]
用法
请注意:MobileTemplateView
应该是第一个父类。
# views.pyfromdjango.views.genericimportTemplateViewfrommobile_template.viewsimportMobileTemplateViewclassHome(MobileTemplateView,TemplateView):template_name='index.html'
模板文件夹结构:
templates ├── base.html ├── index.html └── mobile └── index.html
配置
MOBILE_TEMPLATES_PREFIX
(默认值:mobile/
)-移动模板子文件夹。MOBILE_DOMAIN_REGEX
(默认值:^m.\.*.\.*.*'
)-用于捕获移动域的正则表达式。 默认情况下,它捕获以m.<;domain_或_subdomain>;开头的所有域。