Django Rest Framework - Could not resolve URL for hyperlinked relationship using view name “user-detail”

前端 未结 17 1421
感动是毒
感动是毒 2020-11-28 03:11

I am building a project in Django Rest Framework where users can login to view their wine cellar. My ModelViewSets were working just fine and all of a sudden I get this frus

17条回答
  •  广开言路
    2020-11-28 04:04

    I ran into the same error while I was following the DRF quickstart guide http://www.django-rest-framework.org/tutorial/quickstart/ and then attempting to browse to /users. I've done this setup many times before without problems.

    My solution was not in the code but in replacing the database.

    The difference between this install and the others before was when I created the local database.

    This time I ran my

    ./manage.py migrate
    ./manage.py createsuperuser
    

    immediately after running

    virtualenv venv
    . venv/bin/activate
    pip install django
    pip install djangorestframework
    

    Instead of the exact order listed in the guide.

    I suspected something wasn't properly created in the DB. I didn't care about my dev db so I deleted it and ran the ./manage.py migrate command once more, created a super user, browsed to /users and the error was gone.

    Something was problematic with the order of operations in which I configured DRF and the db.

    If you are using sqlite and are able to test changing to a fresh DB then it's worth an attempt before you go dissecting all of your code.

提交回复
热议问题