gregmuellegger / django-mobile

Detect mobile browsers and serve different template flavours to them.
http://pypi.python.org/pypi/django-mobile
BSD 3-Clause "New" or "Revised" License
560 stars 170 forks source link

some time lost without FLAVOURS_GET_PARAMETER #54

Open BergSoft opened 9 years ago

gregmuellegger commented 9 years ago

Hi, it is intended that the flavour is not set permanently if you don't do so explicitly with the GET paramter. The reason is that you don't lock in users into one flavour forever, but allow to adjust the target with a custom MobileDetectionMiddleware when you go along.

In which cases did you have trouble when the flavour was not set permanently?

shtalinberg commented 9 years ago

flavour was set permanently via GET parameter but after goto link on this page flavour lost. P.S. Sorry for my English.

gregmuellegger commented 9 years ago

@shtalinberg Hi, sorry I don't exactly understand in which cases it is breaking for you. Can you give an example of URLs that is triggering the problem and your settings.MIDDLEWARE_CLASSES setting?

An example of URLs would be:

http://localhost:8000/articles/post/ # shows full flavour
http://localhost:8000/articles/post/?flavour=mobile # shows mobile flavour
http://localhost:8000/articles/post/ # shows full flavour again, but should show mobile
shtalinberg commented 9 years ago

yes - the problem is as you have described in example

my MIDDLEWARE_CLASSES = ( 'corsheaders.middleware.CorsMiddleware', 'subdomains.middleware.SubdomainURLRoutingMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', ......... my apps 'django.contrib.messages.middleware.MessageMiddleware', 'django_mobile.middleware.MobileDetectionMiddleware', 'django_mobile.middleware.SetFlavourMiddleware', ......... my apps 'django.middleware.clickjacking.XFrameOptionsMiddleware', )

gregmuellegger commented 9 years ago

@shtalinberg Ok that looks correct. You need to have cookies enabled to make that work. Please check if you have a cookie with the name flavour set after you have set the flavour with ?flavour=mobile.

shtalinberg commented 9 years ago

yes, I have cookies enabled. but we use session backend

django-mobile

FLAVOURS_GET_PARAMETER = 'setmode' FLAVOURS = ('full', 'mobile') DEFAULT_MOBILE_FLAVOUR = "mobile" FLAVOURS_COOKIE_KEY = 'setmode' FLAVOURS_STORAGE_BACKEND = 'session' # Available values: 'session' and 'cookie'.

gregmuellegger commented 9 years ago

Hm ok, that looks good so far. Can you somehow check that the 'flavour' key is set in your session after you have visited a site with the ?flavour=... GET parameter?