在Django视图中,我很难找到一种简单的方法来检测请求是否来自移动设备.
我正在try 实现这样的功能:
#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兼容?如果没有,还有什么 Select ?