Python作为移动客户端后台服务器

python+flask实现服务器:

安装python和flask略过,servicestest.py代码:

from flask import Flask, jsonify

app = Flask(__name__)

tasks = [
	{
		'id':1,
		'title':u'Buy groceries',
		'description':u'Milk, Cheese, Pizza, Fruit, Tylenol',
		'done': False
	},
	{
		'id':2,
		'title':u'Learn Python',
		'description':u'Need to find a good Python tutorial on the web',
		'done': False
	}
]

@app.route('/todo/api/v1.0/tasks', methods=['GET'])
def get_tasks():
	return jsonify({'tasks': tasks})

if __name__ == '__main__':
	app.run(debug=True)
命令行下:python servicestest.py

之后浏览器:http://127.0.0.1:5000/todo/api/v1.0/tasks就可以看到运行的结果

运行结果:

{
tasks: [
{
description: "Milk, Cheese, Pizza, Fruit, Tylenol",
done: false,
id: 1,
title: "Buy groceries"
},
{
description: "Need to find a good Python tutorial on the web",
done: false,
id: 2,
title: "Learn Python"
}
]
}
建议使用curl:
curl -i http://localhost:5000/todo/api/v1.0/tasks

运行结果:


虽然很简单,毕竟是第一次能运行,还是记录鼓励下自己。

参考:http://www.cnblogs.com/vovlie/p/4178077.html


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值