Hi all,
I would like to know something.
How do you manage the same website but with two modes ?
One mode of a normal browser (safari, chrome, firefox and IE)
and the second for a mobile browser (safari mobile).
Idea, detect the user_agent with
[code]
@app.before_request
def before_request():
if request.user_agent.platform == 'iphone':
prefix = 'mobile_'
else:
prefix = ''
# use the prefix variable with ctx.app.jinja_env variable
@app.route('/')
def index():
return render_template('index.html')
[/code]
Do you have some advices ?
Thanks,
Stephane
lör 2010-08-28 klockan 03:49 +0200 skrev Stephane Wirtel: > Hi all, > > I would like to know something. > > How do you manage the same website but with two modes ? > One mode of a normal browser (safari, chrome, firefox and IE) > and the second for a mobile browser (safari mobile). > > Idea, detect the user_agent with > > [code] > @app.before_request > def before_request(): > if request.user_agent.platform == 'iphone': > prefix = 'mobile_' > else: > prefix = '' > # use the prefix variable with ctx.app.jinja_env variable > > @app.route('/') > def index(): > return render_template('index.html') > [/code] > > Do you have some advices ? > > Thanks, > > Stephane How about make a custom render_template that checks user_agent and prefixes the template name with 'mobile/' if it's a mobile device? User-agent checking is rarely a good idea however. Arguably you should use the same HTML, with good semantics, and just style it with different stylesheets. But practically that's not always easy to get right. Most sites have a different address for the mobile site and maybe redirect with user-agent detection.
Also stylesheets Html4 spec <style type="text/css" media="screen"> <style type="text/css" media="handheld"> the html5 spec introduces some more targeted too -- Thadeus On Fri, Aug 27, 2010 at 8:49 PM, Stephane Wirtel <stephane@wirtel.be> wrote: > Hi all, > > I would like to know something. > > How do you manage the same website but with two modes ? > One mode of a normal browser (safari, chrome, firefox and IE) > and the second for a mobile browser (safari mobile). > > Idea, detect the user_agent with > > [code] > @app.before_request > def before_request(): > if request.user_agent.platform == 'iphone': > prefix = 'mobile_' > else: > prefix = '' > # use the prefix variable with ctx.app.jinja_env variable > > @app.route('/') > def index(): > return render_template('index.html') > [/code] > > Do you have some advices ? > > Thanks, > > Stephane >
I agree with you, it's a point, but the content should be different for the mobile and the computer. But thanks On 28 Aug 2010, at 04:07, Thadeus Burgess wrote: > Also stylesheets > > Html4 spec > <style type="text/css" media="screen"> > <style type="text/css" media="handheld"> > > the html5 spec introduces some more targeted too > > -- > Thadeus > > > > > > On Fri, Aug 27, 2010 at 8:49 PM, Stephane Wirtel <stephane@wirtel.be> wrote: >> Hi all, >> >> I would like to know something. >> >> How do you manage the same website but with two modes ? >> One mode of a normal browser (safari, chrome, firefox and IE) >> and the second for a mobile browser (safari mobile). >> >> Idea, detect the user_agent with >> >> [code] >> @app.before_request >> def before_request(): >> if request.user_agent.platform == 'iphone': >> prefix = 'mobile_' >> else: >> prefix = '' >> # use the prefix variable with ctx.app.jinja_env variable >> >> @app.route('/') >> def index(): >> return render_template('index.html') >> [/code] >> >> Do you have some advices ? >> >> Thanks, >> >> Stephane >>