Table of Contents
回复内容:
Home Backend Development Python Tutorial 如何用python开发移动App(android、iOS)后台?需要掌握哪些技术?

如何用python开发移动App(android、iOS)后台?需要掌握哪些技术?

Jun 06, 2016 pm 04:22 PM
app java json mvc python

本人会移动开发,略知后台开发,不过一般公司都采用java 或者 c开发后台,我想使用python开发移动后台,返回json数据给移动app,我需要怎么做?
1、如果使用python语言,需要学习哪些知识?
2、选择什么样的python框架开发,这个框架的优势?
3、如何部署服务器?本地服务器调试,以及公网服务器部署?
4、如果使用python框架开发移动后台服务,在开发源码内使用哪种框架?mvc还是其它的,比如我返回json数据,每次json对象最外层有一些相同的东西,该如何处理?
5、python的后台服务最大能支持多大的pv量会严重影响用户体验性能?
6、如何兼顾 网页前端以及移动端 开发的后台?
7、有没用相关的案例,即用python开发的移动后台?有没有该问题的开源项目?

回复内容:

1、如果使用python语言,需要学习哪些知识?
python作为一门简单明了的语言,非常容易上手,语言层面不会太复杂,稍微有点难度的顶多就是装饰器、元类和少量函数式编程内容。要说学习的话,我觉得更多是一些编程方面通用的东西,比如:数据结构和算法、设计模式、操作系统、计算机网络之类的

2、选择什么样的python框架开发,这个框架的优势?
tornado,因为非阻塞io的原因,性能非常高,特别适合写后端API(App的后端应该都是rest风格的api),而且成熟稳定

3、如何部署服务器?本地服务器调试,以及公网服务器部署?
这个一两句说不清楚,涉及到运维、测试、开发诸多方面, 部署和测试推荐几个包:fabric、nose、unittest(python自带),版本管理推荐git,持续集成推荐使用docker+jenkins

4、如果使用python框架开发移动后台服务,在开发源码内使用哪种框架?mvc还是其它的,比如我返回json数据,每次json对象最外层有一些相同的东西,该如何处理?
MVC什么的,一般的框架都差不多的,tornado也是支持的,返回json有相同的东西,写个修饰器就完了

5、python的后台服务最大能支持多大的pv量会严重影响用户体验性能?
youtube、reddit、豆瓣、知乎这样的大流量网站都是python写的,我觉得你的App的规模不太可能遇到性能问题,即使有也应该不是python的问题,而是任何语言都会有问题。毕竟web后端不是计算密集型,而是io密集型的,python和其他语言的区别不会太大吧,大量的pv是可以靠堆服务器堆出来的,如果是计算量比较大的任务,你可以考虑用c或c++写

6、如何兼顾 网页前端以及移动端 开发的后台?
用python写的API,网页和移动端都是可以调用啊,让前端学学React,就可以轻松解决前后端分离这个问题(PS: facebook 就是后端php + 前端React,淘宝也有在用nodejs做前后端分离)

7、有没用相关的案例,即用python开发的移动后台?有没有该问题的开源项目?
这个应该比较少,App后端开源的不常见,而且大部分是rest风格的api,很多时候会涉及到自身的业务和敏感信息应该不会开源的吧(又不是bbs或者博客程序)

-------------------------------------------------------------------------------------

关于python学习推荐Full Stack Python ,可以看看这个:
Python 有哪些好的学习资料或者博客? - 彭泉鑫的回答 给一套我用过的解决方案,用来开发过web项目(网页 + ios)和手游项目(ios + 安卓),都是一套后台对应多种前端平台:

web框架:Django
Django 是一套相对全(zhong)面(yong)的框架,基本你要的功能都有,文档很细致,上手比较容易,开发效率比较高。自带 auth、session、orm、admin 等功能,尤其是 admin,如果要求不是太高,用自带的后台管理系统就能省下很多开发工作。

web server:nginx
相对 apache 较轻,简洁。用来部署 django 也比较方便,可参考 Setting up Django and your web server with uWSGI and nginx

数据库:mysql
这个不限定,看业务需求和开发者喜好。当然如果用了 django,自然最好选一个 orm 支持比较好的。

RESTful API:Tastypie
基于 Django 的 RESTful API。Django 本身作为一个 web 框架,返回的结果默认是渲染好的 html 文本。借助 Tastypie,可以比较方便的制作 json 数据格式的接口,将前后端解耦合。这样不管是网页、iOS 还是 Android,都可以用同样的接口。


再针对问题补充一下:
1、如果使用python语言,需要学习哪些知识?
python 语言本身,使用的框架,web 开发的通用知识,比如 HTTP 请求的处理流程、RESTful、OAuth 等。
2、选择什么样的python框架开发,这个框架的优势?
见上文。
3、如何部署服务器?本地服务器调试,以及公网服务器部署?
Django 自带本地调试服务,开发的时候用局域网地址调试即可。公网部署见上文。
4、如果使用python框架开发移动后台服务,在开发源码内使用哪种框架?mvc还是其它的,比如我返回json数据,每次json对象最外层有一些相同的东西,该如何处理?
Tastypie 可以处理掉生成 json 数据时的很多体力活。
5、python的后台服务最大能支持多大的pv量会严重影响用户体验性能?
这个没法给确切答案,具体情况会受机器硬件条件(CPU、内存、I/O)、网络带宽、代码质量、架构设计,甚至配置参数的影响。目前有较大型网站使用 python,并正常运作(参见 有哪些大型公司在使用 Python?有哪些知名项目是主要由 Python 写成的? - Crossin 的回答),所以 python 本身不是问题。实践时,做好压力测试和上线后的性能监控,找出瓶颈不断优化是王道。
6、如何兼顾 网页前端以及移动端 开发的后台?
通过 API,后台无需知道是什么平台在使用它。
7、有没用相关的案例,即用python开发的移动后台?有没有该问题的开源项目?
通常框架会自带测试案例。真实案例开源的暂时不知道。如果哪天我把之前写的开源了,再回来修改答案。 居然有人邀请我回答,甚是激动!
我后台开发水平一般般
除了语言层面的差别,使用Python做后台开发和其他语言开发后台,用到的知识其实是差不多了。除了上面回答提到的数据结构和算法、设计模式、操作系统、计算机网络这些通用的之外,我觉得还需要了解一些后台开发里的基础概念:
IO模型基本概念:异步,同步,阻塞,非阻塞,多路复用(epoll)
并发模型:多进程模型,多线程模型,Reactor模型
Http协议:协议有哪些基本字段,GET和POST的区别
web服务器原理:建议去看看tinyhttp的源码
负载均衡:一些基本的负载均衡算法
网关协议:CGI,FastCGI,WCGI
进程间通讯:管道,消息队列,信号等
其他:session,cookie,Restful API

Python框架用过一个:tornado。tornado框架集成了Web服务器,它是采用目前比较流行异步非阻塞并发模型,性能不错,再加上Python的协程,可以实现一个高性能的web后台。如果使用tornado框架,由于tornado是单进程,不能利用多核CPU,所以部署的时候,可以每个CPU分配一个进程,supervisor守护tornado进程。同时建议使用nginx做前端做负载均衡和管理静态资源。

至于Python性能问题,如果是IO密集型应用,可以考虑用异步IO提高性能。如果是计算密集型,那性能的关键点就用C/C++写吧,Python调用C/C++还是比较方便的。 看需求吧,简单的需求可以直接用Flask,再配上Flask Restful 或者Flask Restless ,辅之以Flask SqlAlchemy 或者直接用SqlAlchemy,数据库Mysql就可以,在弄个Flask Admin加上角色权限管理。就要差不多了
往大说了,要考虑并发,那就很麻烦了,异步的tonardo 就是个不错的选择,还可以用redis做分布式缓存。不过我也没用过,哈哈,也只真正做过基于Flask 的Rest风格的Api 谢邀,如果不复杂,后端直接用postgrest github.com/begriffs/pos 即可。
稍微复杂点的,那就flask,django都行,快速实现。 PYTHON可以用FLASK开发RESTFUL风格的API service。
可以参考这篇文章:
blog.miguelgrinberg.com

不过你要兼顾网页版本移动端开发。PYTHON就不太合适。你应该用Ruby on Rails。原生完美支持html、json、js、xml等方式的请求的响应。做RESTful Web service强大又方便。 可以使用flask框架开发REST API,无论什么平台都能用 最近正在看python自动化开发,alex老师的教程,感觉你可以看看 我们公司用的Flask!感觉比较的灵活!理念也是比较先进! 我公司专做python外包项目。
对这个问题,应该看应用场景来得出一个最佳实践。
首先,是企业应用开发。企业开发经常需要面对变动。需要稳定性和可靠性。这是我们使用的方案是pyramid框架+postgresql数据库,如果图方便就使用uwsgi来管理进程,如果考虑性能还有其他方案。python与pg数据库简直就是天作之合!
tornado也是一个选择,但是应该特别谨慎的使用。因为这是一个异步框架,如果新手很容易造成阻塞。
在实际项目中,我们还经常使用flask和twisted,看应用场景,twisted可以说是一个工业级的框架,我们给一个银行的项目中,twisted的进程曾经连续几年稳定可靠的运行,实在太好用了。
我们还经常用到bottle这个框架,在某些业务场景中还是很好用的。
django反而很少用到,它的orm实在太差了。我们要么使用sqlalchemy,要么就是使用自己封装的一个orm库,速度要快的多,但是简单好用。
总之,应该根据不同的业务选择不同的方案,要知道,在软件这个领域,没有万能的灵丹妙药。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

Python vs. JavaScript: Community, Libraries, and Resources Python vs. JavaScript: Community, Libraries, and Resources Apr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

Detailed explanation of docker principle Detailed explanation of docker principle Apr 14, 2025 pm 11:57 PM

Docker uses Linux kernel features to provide an efficient and isolated application running environment. Its working principle is as follows: 1. The mirror is used as a read-only template, which contains everything you need to run the application; 2. The Union File System (UnionFS) stacks multiple file systems, only storing the differences, saving space and speeding up; 3. The daemon manages the mirrors and containers, and the client uses them for interaction; 4. Namespaces and cgroups implement container isolation and resource limitations; 5. Multiple network modes support container interconnection. Only by understanding these core concepts can you better utilize Docker.

Can visual studio code be used in python Can visual studio code be used in python Apr 15, 2025 pm 08:18 PM

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.

How to run programs in terminal vscode How to run programs in terminal vscode Apr 15, 2025 pm 06:42 PM

In VS Code, you can run the program in the terminal through the following steps: Prepare the code and open the integrated terminal to ensure that the code directory is consistent with the terminal working directory. Select the run command according to the programming language (such as Python's python your_file_name.py) to check whether it runs successfully and resolve errors. Use the debugger to improve debugging efficiency.

Is the vscode extension malicious? Is the vscode extension malicious? Apr 15, 2025 pm 07:57 PM

VS Code extensions pose malicious risks, such as hiding malicious code, exploiting vulnerabilities, and masturbating as legitimate extensions. Methods to identify malicious extensions include: checking publishers, reading comments, checking code, and installing with caution. Security measures also include: security awareness, good habits, regular updates and antivirus software.

Can vs code run in Windows 8 Can vs code run in Windows 8 Apr 15, 2025 pm 07:24 PM

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

Python: Automation, Scripting, and Task Management Python: Automation, Scripting, and Task Management Apr 16, 2025 am 12:14 AM

Python excels in automation, scripting, and task management. 1) Automation: File backup is realized through standard libraries such as os and shutil. 2) Script writing: Use the psutil library to monitor system resources. 3) Task management: Use the schedule library to schedule tasks. Python's ease of use and rich library support makes it the preferred tool in these areas.

See all articles