【问题标题】:Tastypie unable to post with non-id primary keyTastypie 无法使用非 id 主键发布
【发布时间】:2012-01-14 22:44:16
【问题描述】:

我正在使用 django-tastypie 来公开一个 django 模型。但是,我在发布到此资源时遇到了一些问题。似乎tastepie 不喜欢我使用除“id”字段之外的另一个字段作为主键。

这是我看到的错误:

"error_message": "Reverse for 'api_dispatch_detail' with arguments '()' and keyword arguments '{'pk': u'VMware-42 30 21 91 31 77 1b 8a-75 c1 4f ab 70 d9 99 a6', 'api_name': 'v1', 'resource_name': 'system'}' not found.",

我的模特:

class System(models.Model):
    selinux = models.CharField(max_length=255)
    serialnumber = models.CharField(primary_key=True, max_length=255)
    signer = models.CharField(max_length=255)
    tsm_pvu = models.CharField(max_length=255)

我的资源:

class SystemResource(ModelResource):

    class Meta:
            queryset = System.objects.all()
            authentication = ApiKeyAuthentication()
            authorization = DjangoAuthorization()
            resource_name = 'system'

【问题讨论】:

    标签: django tastypie


    【解决方案1】:

    我最近遇到了类似的问题。事实证明,原因不是主键是非 ID 字段,而是主键包含非字母数字字符(例如空格)。您的示例中似乎也可能是这种情况。

    我发现this patch 尚未与主干合并,它为我解决了问题。在tastepie 0.9.11 中需要修补的行是文件tastepie/resources.py 中(方法base_urls)的第283-284 行。希望有帮助。

    【讨论】:

      猜你喜欢
      • 2012-10-15
      • 2014-01-01
      • 1970-01-01
      • 2021-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-28
      • 1970-01-01
      相关资源
      最近更新 更多