我正在努力尋找一種簡單的方法來檢測請求是否來自我的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