[英]Could not resolve URL for hyperlinked relationship
see many post about the similar issue, either not very clear, or I can't understand, so post my problem here again. 看到很多关于类似问题的帖子,要么不是很清楚,要么是我听不懂,所以在这里再次发布我的问题。
I have many other 'xxxList' and 'xxxDetail', all working fine, except this always with exception: 我还有许多其他的“ xxxList”和“ xxxDetail”,它们都工作正常,除了以下例外:
Could not resolve URL for hyperlinked relationship using view name "userinfo-detail".
无法使用视图名称“ userinfo-detail”解析超链接关系的URL。 You may have failed to include the related model in your API, or incorrectly configured the
lookup_field
attribute on this field.您可能无法在API中包含相关模型,或者在此字段上错误地配置了
lookup_field
属性。
Model : 型号 :
class UserInfo(models.Model):
# extend Django user object
user = models.ForeignKey(User, related_name='parkingUser')
Serializer: 串行:
class UserInfoSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = UserInfo
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ('url', 'username', 'is_staff', 'is_active', 'date_joined')
View: 视图:
class UserInfoList(generics.ListCreateAPIView):
queryset = UserInfo.objects.all()
serializer_class = UserInfoSerializer
permission_classes = (permissions.IsAuthenticated,)
def perform_create(self, serializer):
serializer.save(user=self.request.user)
class UserInfoDetail(generics.RetrieveAPIView):
queryset = UserInfo.objects.all()
serializer_class = UserInfoSerializer
permission_classes = (permissions.IsAuthenticated, )
class UserList(generics.ListCreateAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
permission_classes = (permissions.IsAuthenticated, )
class UserDetail(generics.RetrieveAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
permission_classes = (permissions.IsAuthenticated, IsSuperUsersGroupOrDeny)
App Url: 应用网址:
url(r'^usersInfo/$', views.UserInfoList.as_view(), name='userInfo-list'),
url(r'^usersInfo/(?P<pk>[0-9]+)/$', views.UserInfoDetail.as_view(), name='userInfo-detail'),
url(r'^users/$', views.UserList.as_view(), name='user-list'),
url(r'^users/(?P<pk>[0-9]+)/$', views.UserDetail.as_view(), name='user-detail'),
I nearly removed all logic code for testing and it can't be simpler anymore, still the same exception, the weird thing is if I tested the 'userInfoDetail' with standard url in browser like: 我几乎删除了所有逻辑代码以进行测试,并且再也不能再简单了,仍然是一个例外,奇怪的是,如果我在浏览器中使用标准网址测试了“ userInfoDetail”,例如:
http://rest.myDomain.xxx:8090/usersInfo/replaceWithIntegerNumber/
http://rest.myDomain.xxx:8090/usersInfo/replaceWithIntegerNumber/
some of them return the same error, some of them return 其中一些返回相同的错误,其中一些返回
{ "detail": "Not found."
{“ detail”:“未找到。” }
}
what's the problem here? 这是什么问题?
I may be wrong, but the problem seems to be the capital "I" in your usersInfo
URL. 我可能错了,但是问题似乎出在您的
usersInfo
URL中的usersInfo
“ I”上。 Try name='userinfo-list'
and name='userinfo-detail'
instead of name='userInfo-list'
and name='userInfo-detail'
. 尝试使用
name='userinfo-list'
和name='userinfo-detail'
代替name='userInfo-list'
和name='userInfo-detail'
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.