_render_template = flask.render_template

def _my_render_template(*args, **kwargs):
    if detect_mobile_browser(flask.request.user_agent.string):
        args = ('m/' + args[0],) + args[1:]
return _render_template(*args, **kwargs)
flask.render_template = _my_render_template
How to organize code for a Flask application with multiple set of templates