在python视图中检测移动浏览器(不仅仅是iPhone) [英] Detect mobile browser (not just iPhone) in python view
问题描述
我有一个用 Django 编写的 web 应用程序,它有一个特定的页面,我想为其实现模板的移动版本(和稍微不同的逻辑).我希望能够通过这个 sudo 代码实现它:
I have a web application written in Django that has one specific page I'd like to implement a mobile version of the template (and slightly different logic) for. I'd like to be able to implement it ala this sudo code:
def(myView)
do some stuff
if user-is-on-a-mobile-device:
do some stuff
return (my mobile template)
else:
do some stuff
return (my normal template)
我没有太多时间,而且我的编码学习曲线还很早:) - 我发现了一个非常强大的可插拔应用程序,称为bloom,用于获取移动设备功能 - http://code.google.com/p/django-bloom/wiki/BloomDevice但是,它似乎通过 JSON 发出请求以获取我不需要的许多设备规格,这对我来说似乎有点低效.
I don't have a huge amount of time and I'm pretty early on in my coding learning curve :) - I found what looks to be a very powerful pluggable app called bloom for getting mobile device capablities - http://code.google.com/p/django-bloom/wiki/BloomDevice However it seems to make a request via JSON to get lots of device specs I don't need, which seems a bit inefficient to me.
有人建议更简单的方法吗?我的检测不需要100%,只要iPhone、iPod、安卓和主流设备...
Does anyone have a suggest simpler method? My detection doesn't need to be 100%, just iPhone, iPod, android, and mainstream devices...
http_user_agent 字符串是否有某种我可以检查的移动标志?
Does the http_user_agent string have some kind of mobile flag I can check for?
推荐答案
更新:
我刚刚发现:http://code.google.com/p/minidetector/
这似乎完全符合我的要求,我现在要进行测试.随时告诉我我错了!
Which seems to do exactly what I want, I'm going to test now. Feel free to tell me i'm wrong!
这篇关于在python视图中检测移动浏览器(不仅仅是iPhone)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!