基于域/子域动态更改模板的简单应用程序。

django-mobile-template的Python项目详细描述


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

简单的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>;开头的所有域。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java将多个线程中的函数放入单个队列   数组在Java中,如何在不改变整数顺序的情况下找到整数组的顺序?   java控制器属于表示层?   java Apache Ivy和本地Maven repo如何处理使用Maven 3构建的快照   Java可与泛型类型进行比较   java这个表达式在泛型中是什么意思   JavaEclipse和TeamCity插件   java检测构造函数中的final是否为空   java如何在StanfordCoreNLP管道中同时使用词汇化和依赖性解析器?   java在AntUnit控制台日志中显示完整异常堆栈跟踪   lambda如何与Java 8供应商建立连锁关系   如何让GRPC的重试机制在Kubernetes集群中使用grpcjava工作?   如何使用openjdk:7 Docker映像和Gradle包装器避免“EC参数错误”?   java将集合映射扩展为一维映射新的“无法推断函数接口类型”