Flask-Potion is a powerful Flask extension for building RESTful JSON APIs.Potion features include validation, model resources and routes, relations, object permissions, filtering, sorting,pagination, signals, and automatic API schema generation.
Potion ships with backends for SQLAlchemy, peewee and MongoEngine models. It is possible to add backends for other data stores, or even to use a subset of Potion without any data store at all.
API client libraries for Python and JavaScript/TypeScript (generic Node as well as AngularJS and Angular) are available.
The user's guide and documentation is published here:
http://potion.readthedocs.org/
Potion will use semantic versioning from v1.0.0. Until then, the minor version is used for changes known to be breaking.
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_potion import Api, ModelResource, fields
from flask_potion.routes import ItemRoute
app = Flask(__name__)
db = SQLAlchemy(app)
api = Api(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(), nullable=False)
db.create_all()
class UserResource(ModelResource):
class Meta:
model = User
@ItemRoute.GET
def greeting(self, user) -> fields.String():
return "Hello, {}!".format(user.name)
api.add_resource(UserResource)
if __name__ == '__main__':
app.run()
Potion is written and maintained by Lars Schöning.
Peewee backend support has been contributed by Michael Lavers.
MongoEngine backend support has been contributed by João Cardoso.
Time Limit: 1 Second Memory Limit: 65536 KB BaoBao is brewing a magical potion. To brew this potion, types of ingredients, whose rank ranges from 1 to , is needed. More precisely, for all , Ba
2018南京区域赛-Problem I. Magic Potion There are n heroes and m monsters living in an island. The monsters became very vicious these days, so the heroes decided to diminish the monsters in the island. Howe
原题链接:Problem - 1526C1 - Codeforces 题目大意:给你n个数,要你从左到右选择,要sum一直>=0,问你最多可以取多少个数。 这不是普通的01背包了,这个题是有顺序的,可能从前往后有顺序的时候就会有sum<0的时候,所以这里用到优先队列+后悔贪心: 1.有四种情况: 1)a[i]>=0, 直接取, cnt++; 2)a[i] < 0 但是sum + a[i] >= 0
既然知道了段移动的工作原理,让我们重新映射这些命令来使得它们对于Potion文件起作用。 首先我们要决定Potion文件中"段"的意义。 有两对段移动命令,所以我们可以总结出两套组合,我们的用户可以选择自己喜欢的一个。 让我们使用下面两个组合来决定哪里是Potion中的段: 任何在空行之后的,第一个字符为非空字符的行,以及文件首行。 任何第一个字符为非空字符,包括一个等于号,并以冒号结尾的行。 稍
Flask-Potion 是一个强大的扩展用来构建 RESTful JSON APIs。特性包括:数据校验、模型资源、路由、关联、对象权限、过滤、排序、分页、信号和自动化 API schema 生成。Potion 设计用于处理 SQLAlchemy 和 peewee 模型。可集成其他数据存储。 示例代码: from flask import Flaskfrom flask_sqlalchemy i