使用Django rest framework的自定义查找_字段,无法解析detai

2024-06-28 20:21:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我得到的错误是

ImproperlyConfigured at /usercombo/
Could not resolve URL for hyperlinked relationship using view name "usercombo-detail". You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field.

在我的视图.py在

^{pr2}$

在我的序列化程序.py公司名称:

class UserCombo(serializers.HyperlinkedModelSerializer):
    customURL = serializers.CharField(
       required=False,)

    data = JSONSerializerField()

    class Meta:
        model = UserCombo
        unique_together = (("product", "user"),)
        fields = ('url', 'user', 'product', 'data', 'customURL', 'is_active')
        lookup_field ='customURL'

如果我删除两个lookup_字段行,一切正常,但是usercombo对象的lookup_字段是pk。在


Tags: thepyfielddatamodel错误productlookup