【问题标题】:How to use Spyne+Django with parameters on url?如何在 url 上使用带有参数的 Spyne+Django?
【发布时间】:2021-04-13 11:56:14
【问题描述】:

在 django urls.py 上

url(r'soap/<str:user_id>/',
    DjangoView.as_view(application=provider)), 

关于views.py

@ rpc(_returns=AnyDict)
def super_test_dict(self, one, two):
    user_id = 1 #here need to receive the user_id
    res = {"user_id":user_id}
    return res

关于tests.py

self.soap_client = DjangoTestClient(
        f'/soap/{org.str:user_id}/', provider)
res = self.soap_client.service.super_test_dict()

    

问题是当我发送参数 str:user_id 不起作用,但如果没有发送任何正常工作,我需要发送与请求相同的参数但还需要在 url 上发送 str:user_id。

【问题讨论】:

    标签: django xml soap url-parameters spyne


    【解决方案1】:

    您的 super_test_dict 方法的装饰器未反映您期望的输入参数。

    我不确定您到底打算做什么,但要接收输入到您的 Web 服务方法中,请更改您的 views.py 以反映以下内容:

    from spyne import Unicode, Integer
    
    @ rpc(Unicode, Integer, _returns=AnyDict)
    def super_test_dict(self, username, user_id):
        print(f"Hello: {username}, your ID is: {user_id}")
        res = {"user_id":user_id}
        return res
    

    还记得在您的网络服务应用程序中指定 in_protocolout_protocol '提供者'类

    您还可以从这些herehere 获得更多详细信息

    【讨论】:

      猜你喜欢
      • 2021-04-11
      • 2019-07-15
      • 2017-11-14
      • 1970-01-01
      • 2020-08-14
      • 1970-01-01
      • 2020-12-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多