Re: different response for mobile and desktop requests
"Joseph S. Tate" <[email protected]> Fri, 22 Dec 2017 04:09:27 +0000
| Newsgroups | gmane.comp.python.cherrypy |
|---|---|
| Message-ID | <CA+WDQbG_mR5SMV7hBu4BT4E2-N6DNz-U8OJQguFiu-76mUw=FQ@mail.gmail.com> |
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 <[email protected]> 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 cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] > To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected] > 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 cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected] Visit this group at https://groups.google.com/group/cherrypy-users. For more options, visit https://groups.google.com/d/optout.