0
votes

I have some error with Rest API when started Django project.

The error is
"raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'api.urls' from '/Users/luba/code/library/library_project/api/urls.py'>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import."

My code:

api/views.py

from rest_framework import generics

from books.models import Book

from .serializers import BookSerializer



class BookAPIView(generics.ListAPIView):
    queryset = Book.objects.all()
    serializer_class = BookSerializer

api/urls.py

from django.urls import path

from .views import BookAPIView


urlpattens = [
    path('', BookAPIView.as_view()),
]

api/serializers.py

from rest_framework import serializers


from books.models import Book


class BookSerializer(serializers.ModelSerializer):
    class Meta:
        model = Book
        fields = ('title', 'subtitle', 'author', 'isbn')

books/views.py

from django.urls import path

from .views import BookListView

urlpatterns = [
    path('', BookListView.as_view(), name='home'),
]

books/views.py

from django.views.generic import ListView

from .models import Book

class BookListView(ListView):
    model = Book
    template_name = 'book_list.html'

Somebody can explain, in which staff problem with my code.Will be appreciate!!!!

1

1 Answers

1
votes

It seems like you didn't include your api urls to main urls.py

You can find it at same folder where your settings.py is located.

from django.urls import path, include

from api import urls

urlpatterns = [
    path('api/', include(urls.urlpatterns)),
]