首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可以在Python Pyramids Cornice (受Rest启发)中添加子路由吗?

可以在Python Pyramids Cornice (受Rest启发)中添加子路由吗?
EN

Stack Overflow用户
提问于 2018-10-30 19:45:11
回答 1查看 228关注 0票数 0

我正在使用Cornice和金字塔来构建一个API。大多数操作都是REST操作,所以它非常适合。但对于他们中的一些人,我不想遵循REST原则。

例如,在这个类中使用cornice :我们如何在: /gianluca/element/{id}/action下公开一个操作。

我知道我可以有另一个路径为: /gianluca/element/{id}/action的类,带有get或post函数。但我只是想以一种干净的方式使用这个函数。

代码语言:javascript
复制
from cornice.resource import resource
from pyramid.security import Allow
from pyramid.security import Everyone

@resource(collection_path='/gianluca/element', path='/gianluca/element/{id}')
class MyElement(object):

    def __init__(self, request, context=None):
        self.request = request

    def __acl__(self):
        return [(Allow, Everyone, 'everything')]

    def collection_get(self):
        return {'collection': 'all collection'}

    def get(self):
        return "Element id : " + self.request.matchdict['id'] 

    # TODO
    def action(self):
        # elementLib.launchElement() 
        # Just a standart web service not in rest but i would like to have it under :
        # /gianluca/element/{id}/action
        return True
EN

回答 1

Stack Overflow用户

发布于 2019-02-05 22:37:24

为此,您应该使用cornice.Service应用编程接口。cornice.resource是用于纯REST的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53063596

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档