简体   繁体   English

无法解析超链接关系的URL

[英]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.

相关问题 无法解析超链接关系的URL - Could not resolve URL for hyperlinked relationship 另一个无法解决 URL 的超链接关系错误 - Another could not resolve URL for hyperlinked relationship error 嵌套序列化程序:无法使用视图名称解析 URL 的超链接关系 - Nested serializers: Could not resolve URL for hyperlinked relationship using view name 无法解析 URL 与 Django REST 框架的超链接关系 - Could not resolve URL for hyperlinked relationship with Django REST Framework Django Rest 框架 - 配置不当:无法解析 URL 的超链接关系 - Django Rest Framework - ImproperlyConfigured: Could not resolve URL for hyperlinked relationship Django Rest Framework:无法使用视图名称“post-detail”解析超链接关系的 URL - Django Rest Framework: Could not resolve URL for hyperlinked relationship using view name "post-detail" 错误:无法使用视图名称“ api:products-list”解析超链接关系的URL - Error: Could not resolve URL for hyperlinked relationship using view name “api:products-list” 无法使用视图名称“ source-detail” Django解析超链接关系的URL - Could not resolve URL for hyperlinked relationship using view name “source-detail” Django Django Rest Framework - 无法使用视图名称“user-detail”解析超链接关系的 URL - Django Rest Framework - Could not resolve URL for hyperlinked relationship using view name "user-detail" 无法使用视图名称“book-detail”为超链接关系解析 URL - Could not resolve URL for hyperlinked relationship using view name "book-detail"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM