0

My project displays templates separately from PC/tablet and mobile.

  • views.py
...
from django_user_agents.utils import get_user_agent
...

class indexView(View):
    def get(self, request, *args, **kwargs):
        ...
        user = get_user_agent(request)
        if user.is_pc or user.is_tablet:
            template_name = 'web/index.html'     # for PC and Tablet
        else :
            template_name = 'mobile/index.html'  # for Mobile
        ...

However, Galaxy z fold 4 is recognized as tablet when folded and opened in the Chrome browser. In Samsung's basic browser, when folded, it is displayed as a mobile template.

When I checked the userAgent, it included "Safari" instead of "Mobile Safari" in the Chrome browser.

Mozilla/5.0 (Linux; Android 13; SM-F936N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

When the foldable phone is folded, I want to display it as a mobile template on the cover screen in the Chrome browser.

Is there a way to detect a foldable phone in Django? Or if you have another good idea, please recommend it :)

JRR
  • 51
  • 1
  • 4
  • 1
    It's not related to django, you need to configure the layout in a single html template using [media queries](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries) – Ersain Jan 30 '23 at 08:27

1 Answers1

0

As far as I can see only the template changes based on if it is a tablet or pc, you can use a single template which would change based on the aspect ratio of the user.

Arif Rasim
  • 136
  • 2
  • 10