我的urlpatterns中有以下URL:
url(r'^user/(?P<user_pk>[0-9]+)/device/(?P<uid>[0-9a-fA-F\-]+)$', views.UserDeviceDetailView.as_view(), name='user-device-detail'),
注意它有两个字段:user_pk
,和uid
。URL看起来像:https://example.com/user/410/device/c7bda191-f485-4531-a2a7-37e18c2a252c
。
在这个模型的详细视图中,我试图填充一个url
字段,该字段将包含返回模型的链接。
在序列化程序中,我有:
url = serializers.HyperlinkedIdentityField(view_name="user-device-detail", lookup_field='uid', read_only=True)
但是,我认为它失败了,因为URL有两个字段:
django.core.exceptions.ImproperlyConfigured: Could not resolve URL for hyperlinked relationship using view name "user-device-detail". You may have failed to include the related model in your API, or incorrectly configured the
lookup_field
attribute on this field.
当URL有两个或多个URL模板项时,如何使用HyperlinkedIdentityField
(或任何Hyperlink*Field
)?(查找字段)?
目前没有回答
相关问题 更多 >
编程相关推荐