tutorial 4 confusion

32 views
Skip to first unread message

Ben Falk

unread,
Feb 21, 2020, 1:43:08 PM2/21/20
to Django REST framework
First, excellent tutorials, thank you!

Running into a slight problem. In tutorial 4, in the section adding login, it is written that if you "navigate to the '/users/' endpoint" the "representation includes a list of the snippet ids that are associated with each user, in each user's 'snippets' field".

I'm not seeing this.  I only see basic info on each user.  This is the result when I go to the /users/ endpoint:

HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "count": 2,
    "next": null,
    "previous": null,
    "results": [
        {
            "url": "http://localhost:8000/users/2/",
            "username": "doug",
            "email": "",
            "groups": []
        },
        {
            "url": "http://localhost:8000/users/1/",
            "username": "bfalk",
            "email": "",
            "groups": []
        }
    ]
}

Did I miss something in the tutorial?  Or should it read: go to the "/snippets/" endoint (where I do see a connection between each user and a snippet), eg:

        {
            "id": 2,
            "title": "",
            "code": "for x in range(y):\r\n    x",
            "linenos": true,
            "language": "python",
            "style": "friendly",
            "owner": "bfalk"
        },


Thanks, very much.

Ben

Ben Falk

unread,
Feb 21, 2020, 2:57:33 PM2/21/20
to Django REST framework
Ah, I figured it out.  I had my urls.py incorrectly configured.  I modified it slightly from the quickstart for the tutorial, and had

urlpatterns = [
path("", include(router.urls)),
path("api-auth/", include("rest_framework.urls", namespace="rest_framework")),
path("", include("snippets.urls")),
]

Which I think messed it up.

Doing this instead now: 

urlpatterns = [
path("", include("snippets.urls")),
]

urlpatterns += [
path("api-auth/", include("rest_framework.urls")),
]
Reply all
Reply to author
Forward
0 new messages