首页 > 解决方案 > 配置不当的循环导入错误 Django2 Python3

问题描述

即使将语法更新为 django2/python3 兼容,我仍然会收到此错误。经过反复检查,我没有看到错误的命名。

我尝试使用 url 而不是 path 和 django 1 但这仍然不能解决问题

hackuta/urls.py:

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

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',views.HomePage.as_view(),name='home'),
    path('first_app/',include('first_app.urls'),namespace = 'first_app'),
    path('first_app/',include('django.contrib.auth.urls')),
    path('test/',views.TestPage.as_view(),name='test'),
    path('thanks/',views.ThanksPage.as_view(), name='thanks')
]

尝试迁移时显示错误:

File "/home/bbwslayer/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 593, in url_patterns
    raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf 'hackuta.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.

如何解决此问题以顺利迁移?

编辑:我遵循了其中一条评论的建议,事实证明,当我注释掉以下行时,我可以很好地迁移:

    path('first_app/',include('first_app.urls'),namespace = 'first_app'),

我觉得包含 first_app.urls 的代码是合适的:

from django.urls import path
from django.contrib.auth import views as auth_views
from . import views

app_name = 'first_app'
urlpatterns = [
    path('login/',auth_views.LoginView.as_view(template_name = 'first_app/login.html'),name = 'login'),
    path('logout/',auth_views.LogoutView.as_view(),name='logout'),
    path('signup/',auth_views.SignUp.as_view(),name='signup')
]

标签: djangopython-3.x

解决方案


确保每个urls.py都有urlpatterns,如下所示:

urlpatterns = []

另外,请确保您在 in 中添加了右括号urlpatternshackuta/urls.py因为您在问题中将其省略了!


推荐阅读