[Flask] load different templates for mobile website

Ares Ou aresowj at gmail.com
Fri Oct 14 08:54:41 EDT 2016


>From the information you have provided, I guess you could just
write a function receiving path string to return the path for any template
you want to include. By request.MOBILE, this function can determine
to return whether mobile or desktop template path for that particular
template. For example:

import os
> from flask import request, app
> def assemble_template_path(path):
>     if request.MOBILE:
>         return os.path.join(app.config['MOBILE_TEMPLATE_PREFIX'], path)
>     else:
>         # Do not append anything if it's on desktop
>         return path


Best regards,
Ares Ou

*Software Engineer / Full-Stack Python Developer*

*Blog:* http://aresou.net  |  *Github:* https://github.com/aresowj
*Stack Overflow:* http://stackoverflow.com/users/5183727/ares-ou

Ares Ou

On Thu, Oct 13, 2016 at 1:57 PM, Karsten Goen via Flask <flask at python.org>
wrote:

> hello together,
> first of all I do not want to use responsive webdesign, so I need two
> versions of my website since the mobile website shall become a easy
> controllable menu with collapsed menu entries.
> I am really stuck how do I tell flask that it should choose the
> templates out of the mobile folder when detecting a mobile device. I
> already tried this https://flask-mobility.readthedocs.io/en/latest/
> which is very good until that point when you include templates into
> your templates. I think I more need some general loader like:
> when mobile version-> use this template folder (I would use the same
> template names). Would that be the direction to go?
> Another option would be to write a backend api and make two different
> flask-app for each type of website. I think it would not be a big deal
> when using blueprints on the other hand I would prefer one handler in
> my current app which is easy to load and easy to remove when things in
> the app change.
> What you people think? I am open to totally new ideas how to structure
> mobile / desktop website? What would be the best way without rewriting
> "anything".
>
>
> Cheers
>
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20161014/61118241/attachment.html>


More information about the Flask mailing list