I am struggling to find an easy way to detect if the request comes from a mobile device in my Django views.
I am trying to implement something like this:
#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)
And in mytemplate.html:
{% if is_mobile %}
show something
{% else %}
show something else
{% endif %}
Everywhere I checked (for instance here or here), minidetector is recommended. I have installed different versions: pip install minidetector, pip install minidetector2, as well as directly a couple of github repositories, but none of them are compatible