different response for mobile and desktop requests

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

different response for mobile and desktop requests

Andrew-7
Hi,

I would like to serve different html depending on whether the request comes from a mobile or a desktop device. Is this possible with cherrypy?

Thanks.

Andrew

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: different response for mobile and desktop requests

Joseph S. Tate
Do people still do this? I thought you just used different CSS according to "media type". I guess it depends on the site.

Anyway, you'll have to inspect headers. CherryPy won't do this automatically. You can use a custom dispatcher to do that if you want the handlers to be separate, but if you're only varying the output, I'd create a new tool to look at headers and respond with the correct templatized html. (This would make a great contribution back to the community, but we no longer have a tools wiki, so I don't know where it should go.)

I'd make the tool run at before_handler and set something on the cherrypy.request object that tells what the requested layout is.

Then, assuming you're using a templating system like Mako for your HTML Output, I'd fork the mako template tool you're using, and based on the layout value written to the request object by the other tool, chooses a template file from the appropriate place. Maybe you take a dictionary of media-types/layouts to filenames instead of a single template kwarg, or you use a placeholder in the filename that is substituted at runtime. Up to you. Of course if you're using some other template system, substitute accordingly.

Then enable the new tool for every handler, either through the decorator (nah) or through config.

On Thu, Dec 21, 2017 at 7:36 PM Andrew <[hidden email]> wrote:
Hi,

I would like to serve different html depending on whether the request comes from a mobile or a desktop device. Is this possible with cherrypy?

Thanks.

Andrew

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: different response for mobile and desktop requests

David Allouche
People who do not know any better still do this. And it is today just as much a bad idea as it ever was.

For example, it makes it possible to bill two websites: the desktop website and the mobile website.

I think a link to some well maintained library that does User-Agent parsing would be useful here. Because this is really the bigger problem to solve: knowing if the User-Agent is "mobile" (not that it means anything useful, but hey!).

On 22 Dec 2017, at 05:09, Joseph S. Tate <[hidden email]> wrote:

Do people still do this? I thought you just used different CSS according to "media type". I guess it depends on the site.

Anyway, you'll have to inspect headers. CherryPy won't do this automatically. You can use a custom dispatcher to do that if you want the handlers to be separate, but if you're only varying the output, I'd create a new tool to look at headers and respond with the correct templatized html. (This would make a great contribution back to the community, but we no longer have a tools wiki, so I don't know where it should go.)

I'd make the tool run at before_handler and set something on the cherrypy.request object that tells what the requested layout is.

Then, assuming you're using a templating system like Mako for your HTML Output, I'd fork the mako template tool you're using, and based on the layout value written to the request object by the other tool, chooses a template file from the appropriate place. Maybe you take a dictionary of media-types/layouts to filenames instead of a single template kwarg, or you use a placeholder in the filename that is substituted at runtime. Up to you. Of course if you're using some other template system, substitute accordingly.

Then enable the new tool for every handler, either through the decorator (nah) or through config.

On Thu, Dec 21, 2017 at 7:36 PM Andrew <[hidden email]> wrote:
Hi,

I would like to serve different html depending on whether the request comes from a mobile or a desktop device. Is this possible with cherrypy?

Thanks.

Andrew

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.