在我的Flask-RESTful API中,假设我有两个对象,用户和城市.这是1对多的关系.现在,当我创建API并向其添加资源时,我似乎只能将非常简单的常规URL映射到它们.这是代码(没有包含无用的东西):
class UserAPI(Resource): # The API class that handles a single user
def __init__(self):
# Initialize
def get(self, id):
# GET requests
def put(self, id):
# PUT requests
def delete(self, id):
# DELETE requests
class UserListAPI(Resource): # The API class that handles the whole group of Users
def __init__(self):
def get(self):
def post(self):
api.add_resource(UserAPI, '/api/user/<int:id>', endpoint='user')
api.add_resource(UserListAPI, '/api/users/', endpoint='users')
class CityAPI(Resource):
def __init__(self):
def get(self, id):
def put(self, id):
def delete(self, id):
class CityListAPI(Resource):
def __init__(self):
def get(self):
def …Run Code Online (Sandbox Code Playgroud) 我正在开发一个"预测模型即服务"的应用程序,结构如下:
我正在尝试使用patsy,但遇到以下问题:当单个预测进入时,如何将其转换为正确的形状,使其看起来像一行训练数据?
patsy文档提供了一个示例,当训练数据中的DesignInfo在内存中可用时:http://patsy.readthedocs.io/en/latest/library-developers.html#predictions
# offline model training
import patsy
data = {'animal': ['cat', 'cat', 'dog', 'raccoon'], 'cuteness': [3, 6, 10, 4]}
eq_string = "cuteness ~ animal"
dmats = patsy.dmatrices(eq_string,data)
design_info = dmats[1].design_info
train_model(dmats)
# online predictions
input_data = {'animal': ['raccoon']}
# if the DesignInfo were available, I could do this:
new_dmat = build_design_matrices([design_info], input_data)
make_prediction(new_dmat, trained_model)
Run Code Online (Sandbox Code Playgroud)
然后是输出:
[DesignMatrix with shape (1, 3)
Intercept animal[T.dog] animal[T.raccoon]
1 0 1
Terms:
'Intercept' (column 0)
'animal' (columns …Run Code Online (Sandbox Code Playgroud) 所以我从头开始创建一个全新的Flask应用程序.正如所有优秀的开发人员所做的那样,我的第一步是创建虚拟环境.
我在虚拟环境中安装的第一件事是Flask==0.11.1.Flask安装以下依赖项:
- 点击== 6.6
- itsdangerous == 0.24
- Jinja2的== 2.8
- MarkupSafe == 0.23
- WERKZEUG == 0.11.11
- 轮== 0.24.0
现在,我创建了一个requirements.txt,以确保每个克隆存储库的人都拥有相同版本的库.但是,我的困境是这样的: