【问题标题】:"Dynamic" datasource in python eve?python eve中的“动态”数据源?
【发布时间】:2020-12-02 01:14:13
【问题描述】:

我怎样才能从传入的后有效负载中获得一种动态数据源? 因此,所有传入的有效负载在 mongodb 中“创建”一个新集合,或者使用旧的集合(如果可用)...

例如。有效载荷: {“a1”:“999”,“d1”:“06.05.2020 04:29:16”,“d2”:“0”,“d3”:“0”,“id2” :“3777”}

settings.py 的一部分:

mdata = {
    'schema': {
            **'a1': {
                'type': 'string'**
            },
            'd1': {
                'type': 'string'
            },
            'd2': {
                'type': 'string'
            },
            'd3': {
                'type': 'string'
            },
            'id2': {
                'type': 'string'
            }
        },
    'datasource': {
            **'source': "a1-value" #should be 'a1' value from the post payload**
        },
    "resource_methods": ["POST"],
    }

DOMAIN = {
    "accounts": accounts,
    "user": user,
    "mdata": madata,
    }

【问题讨论】:

    标签: eve


    【解决方案1】:

    eve中,集合名就是你的资源名:

    例如,假设这是您的DOMAIN

    DOMAIN = {
        'test': <your_test_endpoint_variable>,
    }
    

    因此,当您请求此端点时,将创建一个名称为 test 的集合。

    但是source

    资源使用的数据库集合的名称。如果省略,则假定资源名称也是有效的集合名称。

    我建议阅读文档的这一部分:

    https://docs.python-eve.org/en/stable/config.html#advanced-datasource-patterns

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-24
      • 2017-05-15
      • 1970-01-01
      • 2015-09-25
      • 2016-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多