标签:html code 指定 htm name run bubuko rip not found
from flask import Flask, jsonify, abort from flask_script import Manager app = Flask(__name__) manage = Manager(app) #获取数据 #posts=[]不能写成{} posts=[ { ‘id‘:1, ‘title‘:‘python基础‘, ‘content‘:‘人生苦短我用Python‘ },{ ‘id‘:2, ‘title‘:‘HTML基础‘, ‘content‘:‘几个标签的故事‘ } ] #获取资源列表 @app.route(‘/posts/‘) def get_posts_list(): return jsonify({‘posts‘:posts}) #获取指定资源 @app.route(‘/posts/<int:pid>/‘) def get_posts(pid): p= list(filter(lambda p:p[‘id‘] ==pid,posts)) if len(p)==0: # return ‘数据不存在‘ abort(404) return jsonify({‘posts‘:p[0]}) #定制404错误显示 @app.errorhandler(404) def page_not_found(e): return jsonify({ ‘error‘:‘page not found‘ }),404 @app.route(‘/‘) def hello_world(): return ‘原生实现restful‘ if __name__ == ‘__main__‘: manage.run()
这只是一个简单的原生flask restful,不喜勿喷。2018-12-062018-12-06
标签:html code 指定 htm name run bubuko rip not found
原文地址:https://www.cnblogs.com/liangliangzz/p/10078367.html