# Django REST API 404

**URL:** <https://forum.djangoproject.com/t/django-rest-api-404/17320>\
**Category:** Forms & APIs\
**Created:** [November 28, 2022, 3:57pm UTC](https://forum.djangoproject.com/t/django-rest-api-404/17320 "2022-11-28T15:57:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![biscotty666](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/biscotty666/32/10522_2.png) [@biscotty666](https://forum.djangoproject.com/u/biscotty666)\
**Post date:** [November 28, 2022, 3:57pm UTC](https://forum.djangoproject.com/t/django-rest-api-404/17320/1 "2022-11-28T15:57:21Z")

</div>

Hi,  
I’m trying to implement Django’s REST Api. I followed the [tutorial](https://www.django-rest-framework.org/tutorial/quickstart/) and everything compiles fine and all other parts of the app work but when I try to access the url at [http://app.url/players](http://app.url/players) I get the page not found. Can anyone help me with this?

Thanks in advance.

PS: if I try to create the url in the normal manner with a path statement I get an error that I supplied 2 positional arguments instead of 1. So it looks like 2 problems perhaps.

serializers.py

```auto
from .models import Player
from rest_framework import serializers

class PlayerSerializer(serializers.HyperlinkedModelSerializer):
  class Meta:
    model = Player
    fields = ['name', 'gp']

```

views.py

```auto
from rest_framework import viewsets
from rest_framework import permissions
from Striker.serializers import PlayerSerializer

```

urls.py

```auto
from django.contrib import admin
from django.urls import path, include
from rest_framework import routers
from Striker import views

router = routers.DefaultRouter()
router.register(r'players/', views.PlayerViewSet)

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('Striker.urls')),
    path('api-auth/', include('rest_framework.urls'), name='rest_framework')
]

```

class PlayerViewSet(viewsets.ModelViewSet):  
queryset = Player.objects.all().order\_by(‘-gp’)  
serializer\_class = PlayerSerializer  
permission\_class = [permissions.IsAuthenticated]

```auto
models.py

```

class Player(models.Model):  
name = models.CharField(max\_length=30)  
gp = models.IntegerField()

```auto

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [November 28, 2022, 4:53pm UTC](https://forum.djangoproject.com/t/django-rest-api-404/17320/2 "2022-11-28T16:53:44Z")

</div>

You are registering the url:

> [@biscotty666](#):
>
> ```auto
> router.register(r'players/', views.PlayerViewSet)
> 
> ```

But you’re trying to access:

> [@biscotty666](#):
>
> `http://app.url/players`

The two are not the same. (You’re missing the trailing slash on the url.)

---

<div class="post-metadata">

**Author:** ![biscotty666](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/biscotty666/32/10522_2.png) [@biscotty666](https://forum.djangoproject.com/u/biscotty666)\
**Post date:** [November 28, 2022, 5:17pm UTC](https://forum.djangoproject.com/t/django-rest-api-404/17320/3 "2022-11-28T17:17:46Z")

</div>

Thanks for the reply but I get the 404 whether or not I supply a trailing slash on the url. I also tried removing the trailing slash from the router.register statement but same problem.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [November 28, 2022, 5:26pm UTC](https://forum.djangoproject.com/t/django-rest-api-404/17320/4 "2022-11-28T17:26:15Z")

</div>

Ahh, I also don’t see where you are mapping your `router` urls in your `urlpatterns`. (See the example at [Quickstart - Django REST framework](https://www.django-rest-framework.org/tutorial/quickstart/#urls))

---

<div class="post-metadata">

**Author:** ![biscotty666](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/biscotty666/32/10522_2.png) [@biscotty666](https://forum.djangoproject.com/u/biscotty666)\
**Post date:** [November 28, 2022, 5:31pm UTC](https://forum.djangoproject.com/t/django-rest-api-404/17320/5 "2022-11-28T17:31:31Z")

</div>

“Because we’re using viewsets instead of views, we can automatically generate the URL conf for our API, by simply registering the viewsets with a router class”

Isn’t that what my code does?

(That is the doc I’m looking at.)

---

<div class="post-metadata">

**Author:** ![biscotty666](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/biscotty666/32/10522_2.png) [@biscotty666](https://forum.djangoproject.com/u/biscotty666)\
**Post date:** [November 28, 2022, 5:40pm UTC](https://forum.djangoproject.com/t/django-rest-api-404/17320/6 "2022-11-28T17:40:27Z")

</div>

OK, I just added ‘urlpatterns += router.urls’ and it’s all good. Thanks for your patience, Ken.
