我正在努力寻找一种简单的方法来检测请求是否来自我的Django视图中的移动设备。使用Django和Python 3检测移动设备
我想实现这样的事情:
#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
所以在这里,我的问题兼容:有minidetector的任何版本/前叉是兼容与Python 3?如果不是,有什么选择?
有链接到一个无关紧要的问题AttributeError的。发布您的堆栈跟踪 – e4c5
该链接旨在显示minidetector与Python 3不兼容。为了避免对该问题本身造成混淆,我已将其删除并重新说明了该部分。 – J0ANMM