【发布时间】:2017-07-05 12:38:55
【问题描述】:
我正在努力寻找一种简单的方法来检测请求是否来自我的 Django 视图中的移动设备。
我正在尝试实现这样的东西:
#views.py
def myfunction(request):
...
if request.mobile:
is_mobile = True
else:
is_mobile = False
context = {
... ,
'is_mobile': is_mobile,
}
return render(request, 'mytemplate.html', context)
在mytemplate.html:
{% if is_mobile %}
show something
{% else %}
show something else
{% endif %}
在我检查过的所有地方(例如here 或here),推荐minidetector。我安装了不同的版本:pip install minidetector、pip install minidetector2,以及直接安装了几个 github 存储库,但没有一个与 Python 3 兼容。
所以我的问题是:是否有任何与 Python 3 兼容的 minidetector 版本/分支?如果没有,有什么替代方案?
【问题讨论】:
-
您已链接到一个无关的 AttributeError 问题。发布您的堆栈跟踪
-
该链接旨在表明 minidetector 与 Python 3 不兼容。我已将其删除并重新表述了该部分,以避免对问题本身造成任何混淆。
标签: django python-3.x user-agent mobile-website