如何检查Django 1.9中用户是否正在使用移动设备? [英] How do I check if a User is using a mobile device in Django 1.9?

查看:86
本文介绍了如何检查Django 1.9中用户是否正在使用移动设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Django 1.9与Python 2.7结合使用,并且试图使我的应用程序能够识别用户是否正在使用移动设备进行浏览.我已经尝试过django_mobile了,但是对于django 1.9来说似乎已经过时了,因为甚至没有template_loaders来安装该应用程序,我对此是否有错?

I'm using Django 1.9 with Python 2.7 and I'm trying to get my app to recognize if the user is browsing with a mobile device. I've tried django_mobile but it seems outdated for django 1.9 because there aren't even template_loaders to install the app, am I wrong about this?

推荐答案

,或者您可以使用 django-user_agents 应用.真的很好.您还可以在模板中获得上下文-其中对于根据设备呈现某些广告很重要

or you can use django-user_agents app. really good one. you also get the context in your template - among others important for rendering some ads depending on device

可见

request.user_agent.is_mobile

或在模板中

{% if request.user_agent.is_mobile %}
    Do stuff here...
{% endif %}

这篇关于如何检查Django 1.9中用户是否正在使用移动设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆