django - 配置不当的循环导入错误 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')
]
解决方案
确保每个urls.py
都有urlpatterns,如下所示:
urlpatterns = []
另外,请确保您在 in 中添加了右括号urlpatterns
,hackuta/urls.py
因为您在问题中将其省略了!
推荐阅读
- scala - Spark:加载具有不同列数的 CSV
- c# - 通过在代码中设置高度和宽度来缩小视图大小不会正确更新
- drupal-7 - 如何从 Drupal 7.x 的块中访问属性
- database - 如何根据另一个已完成表单的 ID 打开第二个表单?
- amazon-web-services - 您可以使用 AWS CLI 执行 AND/OR 类型查询吗?
- xpages - 自动完成似乎没有“接受”
- ibm-watson - 可解释性功能是否支持批处理?
- mysql - 如何在查询中将多个表连接在一起
- reactjs - React Emoji Picker 未转换为 unicode
- javascript - Gatsby 构建 html 内容为空