【发布时间】:2025-11-22 19:50:02
【问题描述】:
因为我正在使用 django_admin 加载我的页面。有人可以告诉我如何禁用加载某些移动项目吗?我在网上搜索过,但找不到任何东西。
【问题讨论】:
标签: python django django-forms django-templates
因为我正在使用 django_admin 加载我的页面。有人可以告诉我如何禁用加载某些移动项目吗?我在网上搜索过,但找不到任何东西。
【问题讨论】:
标签: python django django-forms django-templates
你可以这样解决你的问题:
views.py 文件
def mobile_view(request):
...
is_mobile = request.user_agent.is_mobile
context = {
.....
'is_mobile': is_mobile
}
return render(request, 'app/yourHTML.html', context)
你的HTML.html
<!DOCTYPE html>
......
{{ if is_mobile }}
//Keep the content here to be displayed to the mobile device.
{{ else }}
//Content to be hidden from mobile device.
{{ endif }}
</html>
或者你也可以试试这个
你的HTML.html
<!DOCTYPE html>
......
{{ if request.user_agent.is_mobile }}
//Keep the content here to be displayed to the mobile device.
{{ else }}
//Content to be hidden from mobile device.
{{ endif }}
</html>
【讨论】: