移动请求的django标志?
我想要一个flag变量来测试django中的移动页面 目前,我们需要在python视图、django模板、javascripts和handlebar模板上使用该标志 它将类似于{%if\u testing\u mobile%}做点什么。。{%endif%} 我们只为手机和pc提供了几个不同的页面。 大多数页面都被bootstrap的流畅性所覆盖 我们如何设置变量来打开或关闭手机/电脑?试试这个 page.html:移动请求的django标志?,django,mobile,Django,Mobile,我想要一个flag变量来测试django中的移动页面 目前,我们需要在python视图、django模板、javascripts和handlebar模板上使用该标志 它将类似于{%if\u testing\u mobile%}做点什么。。{%endif%} 我们只为手机和pc提供了几个不同的页面。 大多数页面都被bootstrap的流畅性所覆盖 我们如何设置变量来打开或关闭手机/电脑?试试这个 page.html: 我建议添加一个中间件,如果对象来自移动设备,它将设置一些参数来请求对象 您可以像
我建议添加一个中间件,如果对象来自移动设备,它将设置一些参数来请求对象 您可以像前面的回答中提到的那样自己编写一个中间件,或者使用这个第三方应用程序: 注意:其他应用程序也提供不同级别的移动检测功能:
from minidetector import detect_mobile
@detect_mobile
def my_mobile_view(request):
is_mobile = False
if request.mobile:
is_mobile = True
#do something with mobile
render(request, 'page.html', {'is_mobile': is_mobile})
{% if is_mobile %}
render the mobile css
{% else %}
render the pc css
{% endif %}