首页 > 解决方案 > 如何跟踪循环导入错误 Django 从未解决

问题描述

我正在工作 Django rest framework api 项目,我在项目中有多个应用程序。将应用程序 URL 添加到主 URL 时出现循环导入错误。我尝试了所有检查拼写,检查应用程序结构但没有用的东西。问题真的很令人沮丧。请帮助解决问题。当我取消新添加的线路时,该应用程序运行良好path("covid/", include("Covid.urls")),

我正在使用 python3.6、django 3.0.4 和 django-rest-framework 3.11.0

这是项目 urls.py

from django.contrib import admin
from django.conf.urls import url
from django.urls import path, include
from rest_framework_swagger.views import get_swagger_view

schema_view = get_swagger_view(title='TmmrwInc API Documentation')

urlpatterns = [
    path('admin/', admin.site.urls),
    # path('', include('django.contrib.auth.urls')),
    # path('rest_auth/', include('rest_auth.urls')),
    path('api/password_reset/',
        include('django_rest_passwordreset.urls', namespace='password_reset')),
    # url(r'^invitations/', include('invitations.urls', namespace='invitations')),
    path('', include('rest_invitations.urls')),
    path("", include("UserAuth.urls")),
    path("doctors/", include("Administration.urls")),
    path("appointments/", include("Appointments.urls")),
    path("messaging/", include("messaging.urls")),
    path("meet/", include("meet.urls")),
    path("api_documentation/", schema_view),
    path("covid/", include("Covid.urls")),
]

这是应用程序urls.py文件

from django.urls import path
from . import views

app_name = 'Covid'

urlpatterns = [
    path('event/', views.EventBookingView.as_view()),
]

settings.py安装的应用程序

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.sites",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "UserAuth",
    "rest_framework",
    "corsheaders",
    'rest_framework.authtoken',
    'rest_auth',
    'Appointments',
    'messaging',
    'Administration',
    'channels',
    'invitations',
    'rest_invitations',
    'django_rest_passwordreset',
    'django_celery_beat',
    'meet',
    'rest_framework_swagger',
     'Covid',

]

这是我的应用程序views.py文件

from django.shortcuts import render
from rest_framework.generics import CreateAPIView, RetrieveAPIView, ListAPIView, UpdateAPIView
from rest_framework.permissions import IsAuthenticated, AllowAny
from rest_framework.response import Response
from rest_framework import status, viewsets

from .serializers import OfficeSearchSerializer, EventSerializer, SymptomSerializer, PatientSymptomSerializer

# Create your views here

class OfficeSearchView(ListAPIView):
    serializer_class = OfficeSearchSerializer
    permission_class = (AllowAny,)
    lookup_field = 'pk'



class EventBookingView(CreateAPIView):
    serializer_class = EventSerializer
    permission_class = (AllowAny, )

这是一个项目结构

项目结构

标签: djangodjango-rest-frameworkdjango-viewspython-3.6django-urls

解决方案


推荐阅读