mercredi 8 mai 2019

Circular import error when I open the Django server

When I open the server(Django) I get this error: "The included URLconf 'admin.urls' 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."

I have found out that by removing .views import from urls.py I fix the issue. So I think the problem is inside views.py.

App urls.py

from django.contrib import admin
from django.urls import include
from django.urls import path

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

views.py

from django.shortcuts import render
from rest_framework.response import Response
from rest_framework.views import APIView

from .models import User
from .serializers import UserSerializer

class UserView(APIView):
    def get(self, request):
        users = User.objects.all()
        serializer = UserSerializer(users, many=True)
        return Response({"users": users})

serializer.py

from rest_framework import serializers

class UserSerializer(serializers.Serializer):
    name = serializers.CharField(max_length=255)
    email = serializers.EmailField()
    password = serializers.CharField(max_length=255)
    disease = serializers.CharField(max_length=255)
    logo = serializers.TextField()


crud urls.py

Here, the issue is at the second line: if I remove that line I fix the error

from django.urls import path
from .views import UserView

app_name='crud'
# app_name will help us do a reverse look-up latter.
urlpatterns = [
    path('users/', UserView.as_view()),
]




Aucun commentaire:

Enregistrer un commentaire