1
hepochen Jun 14, 2014 via iPhone
headers判断
|
2
moroumo Jun 14, 2014
应该用响应式设计去处理页面。
不过看你的想法不同的UA redern不同的template。 http://stackoverflow.com/questions/9878020/how-do-i-get-the-user-agent-with-flask |
5
yelite Jun 14, 2014
判断 header,移动端只是要获取数据的话就设置 request 的 header
Accept: application/json |
6
yangzh Jun 14, 2014
|
7
tokki Jun 14, 2014
重新写个函数类似
render(tpl): |
8
tokki Jun 14, 2014
render(tpl):
if mobile: return render_template("mobile/“+tpl) else return render_template(tpl) |
9
Livid MOD PRO |
10
billlee Jun 14, 2014
功能不同的接口就不要用同一个名称,把 API 放到 /api/login
|
11
ccbikai PRO 要做API就做API,要做网页就做网页,不要搞到一个路由里。
判断移动端,就处理一下UA,判断UA是否是移动设备 if mobile: return "mobiile" else: return "desktop" |
13
cbsw Jun 14, 2014 这样的需求是不是应该考虑 RESTful,而且有 http://flask-restful.readthedocs.org/en/latest/ 这个现成的库可以用
|
16
jxwho OP @cbsw 比如说,我有一个post资源,
然后 index 页面要展示这些 post 的话,是不是用户访问 /index,然后处理函数再请求post的get? 然后 如果 mobile的话,可以直接 /post/get 这样? |
17
cbsw Jun 14, 2014
@jxwho web 端用 restful 的话,大部分操作都要通过异步 ajax 实现,应用可以直接是一个静态页面,具体可以参考 https://github.com/miguelgrinberg/REST-tutorial ,另外玩 flask 可以关注一下 miguelgrinberg 这个人,博客(http://blog.miguelgrinberg.com/)里有很多非常好的 tutorial
|
19
zjnjxufe Jul 16, 2014
if request.user_agent.platform in ('android', 'iphone'):
return xxx |