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