将sqlalchemy模型的结构公开为restful api的模块
modelstruct的Python项目详细描述
modelStruct
==
一个简单的python模块,将sqlalchemy模型结构公开为restful api。
主键=真)
创建时间=db.column(db.datetime)
名称=db.column(db.string(140),唯一=真)
说明=db.column(db.string(320))
在目录中=db.column(db.boolean,默认=真)
用户ID=db.column(db.integer)
作者=db.column(db.string(140))
定义初始(self,name,author,description,in-u inventory,user-id:
self.name=name
self.description=description
self.in-inventory=in-u inventory
self.user-id=user-id
self.time=datetime.datetime.now()
self.author=author
def-repr-uu(self):
return'<;book%r>;'%self.id
```
``json
{
“structure”:{
“author”:“varchar(140)”,
“description”:“varchar(320)”,
“id”:“integer”,
“in_inventory”:“boolean”,
“name”:“varchar(140)”,
“创建时间”:“日期时间”,
“用户id”:“整数”
}
}
````
导入python模块
`` python
从modelstruct import get_json
```
2。为要成为API的端点创建一个新路由(下面的示例位于flask中,并在位置`/models`,使用模型类名称`model\name\u here`)创建API
``python
@app.route('/models',methods=['get'])
def get\u model\u structure():
return get\u json(model\name\u here)
```
>3。就这样!向端点发送get请求并获取模型的结构。
==
一个简单的python模块,将sqlalchemy模型结构公开为restful api。
主键=真)
创建时间=db.column(db.datetime)
名称=db.column(db.string(140),唯一=真)
说明=db.column(db.string(320))
在目录中=db.column(db.boolean,默认=真)
用户ID=db.column(db.integer)
作者=db.column(db.string(140))
定义初始(self,name,author,description,in-u inventory,user-id:
self.name=name
self.description=description
self.in-inventory=in-u inventory
self.user-id=user-id
self.time=datetime.datetime.now()
self.author=author
def-repr-uu(self):
return'<;book%r>;'%self.id
```
``json
{
“structure”:{
“author”:“varchar(140)”,
“description”:“varchar(320)”,
“id”:“integer”,
“in_inventory”:“boolean”,
“name”:“varchar(140)”,
“创建时间”:“日期时间”,
“用户id”:“整数”
}
}
````
导入python模块
`` python
从modelstruct import get_json
```
2。为要成为API的端点创建一个新路由(下面的示例位于flask中,并在位置`/models`,使用模型类名称`model\name\u here`)创建API
``python
@app.route('/models',methods=['get'])
def get\u model\u structure():
return get\u json(model\name\u here)
```
>3。就这样!向端点发送get请求并获取模型的结构。