Error: Could not resolve URL for hyperlinked relationship using view name

376 views
Skip to first unread message

Joe Cabrera

unread,
Dec 13, 2016, 1:04:28 PM12/13/16
to Django REST framework
Hi,

I upgraded from DRF 2.4x to DRF 3.5.3 and Django 1.7.4 to Django 1.10.3 and am in the process of converting code to use the new API. 

My code is now returning the error: 
Could not resolve URL for hyperlinked relationship using view name "company-detail". You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field.


My serializer(s):

class CompanyShortSerializer(serializers.HyperlinkedModelSerializer):

    name = serializers.CharField()

    logo = HyperlinkedFileField()

    description = serializers.CharField()


    class Meta:

        model = Company

        fields = ('id', 'url', 'name', 'description')

        extra_kwargs = {

            'url': {'view_name': 'hired:company-detail'}

        }


class CompanyUserReadSerializer (serializers.HyperlinkedModelSerializer):

    owner = UserSerializer(read_only=True)

    company = CompanyShortSerializer()

    title = EscapedCharField()

    role = EscapedCharField()


    class Meta:

        model = CompanyUser

        fields = (

            'url', 'id', 'owner', 'company', 'title', 'role', 'is_verified','is_demo','color'

        )

        read_only_fields = ('is_verified',)



Timo Piirmann

unread,
Dec 16, 2016, 2:11:29 AM12/16/16
to Django REST framework
Can't be sure unitl you show your view/url files but this here seems to be a bit fishy

extra_kwargs = {
    'url': {'view_name': 'hired:company-detail'}
}

 I'm not sure that 'hired:' with ':' is a valid thing. If you have a model named Company and you havent't specified any special view names for that route then "company-detail" should be enough
Reply all
Reply to author
Forward
0 new messages