Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Django REST Framework RESTful Django Create a ListView

No module named django.urls?

Why isn't this module recognised? Here is the official doc: https://docs.djangoproject.com/en/2.2/ref/urls/

scorekeeper/views.py
from rest_framework.views import APIView
from rest_framework.response import Response

from . import models
from . import serializers


class GameList(APIView):
    def get(self, request, format=None):
        games = models.Game.objects.all()
        serializer = serializers.GameSerializer(games, many=True)
        return Response(serializer.data)
scorekeeper/urls.py
from django.conf.urls import url
from django.urls import path

from . import views


urlpatterns = [
    path('games/', views.GameList.as_view(), name='game_list')
]

1 Answer

Eric Cahanin
Eric Cahanin
14,868 Points

I think they're using an older version of django - one of the videos mentioned 1.9, and django.urls was added in 2.0.