无法找到上述错误的根源:我已经查看了以下链接,并且提供的解决方案未能解决我的问题:Django - Circular model import issue
以下网址似乎导致出现循环导入错误。注释掉后,该错误不会出现。
simplesocial / urls.py
urlpatterns = [
url(r"^$", views.HomePage.as_view(), name="home"),
url(r"^test/$", views.TestPage.as_view(), name="test"),
url(r"^thanks/$", views.ThanksPage.as_view(), name="thanks"),
url(r"^admin/", admin.site.urls),
url(r"^accounts/", include("accounts.urls", namespace="accounts")), #causes circular
reference
url(r"^accounts/", include("django.contrib.auth.urls")), # causes circular reference
url(r"^posts/", include("posts.urls", namespace="posts")), # causes circular reference
url(r"^groups/",include("groups.urls",namespace="groups")),
帐户/urls.py
from django.conf.urls import url
from django.contrib.auth import views as auth_views
from . import views
app_name = 'accounts'
urlpatterns = [
url(r"^$", views.LoginView.as_view(), name="login"), #works, review
#url(r"^login/$",accounts.views.LoginView,name="login"),#additional url pattern. test.
#url(r"^$", views.LoginView.as_view(template_name="accounts/login.html"), name="login"),#test. does this work??
url(r"login/$", auth_views.LoginView.as_view(template_name="accounts/login.html")),
url(r"logout/$", auth_views.LogoutView.as_view(), name="logout"),
url(r"signup/$", views.SignUp.as_view(), name="signup"),
]
groups / urls.py
from django.conf.urls import url
from . import views
app_name = 'groups'
urlpatterns = [
url(r"^$", views.ListGroups.as_view(), name="all"),
url(r"^new/$", views.CreateGroup.as_view(), name="create"),
url(r"^posts/in/(?P<slug>[-\w]+)/$",views.SingleGroup.as_view(),name="single"),
url(r"join/(?P<slug>[-\w]+)/$",views.JoinGroup.as_view(),name="join"),
url(r"leave/(?P<slug>[-\w]+)/$",views.LeaveGroup.as_view(),name="leave"),
]
posts / urls.py
from django.conf.urls import url
from . import views
app_name='posts'
urlpatterns = [
url(r"^$", views.PostList.as_view(), name="all"),
url(r"new/$", views.CreatePost.as_view(), name="create"),
url(r"by/(?P<username>[-\w]+)/$",views.UserPosts.as_view(),name="for_user"),
url(r"by/(?P<username>[-\w]+)/(?P<pk>\d+)/$",views.PostDetail.as_view(),name="single"),
url(r"delete/(?P<pk>\d+)/$",views.DeletePost.as_view(),name="delete"),
]
但是,当从simplesocial/urls.py
文件中注释掉以下3行时。
返回以下错误:
NoReverseMatch at /
'accounts' is not a registered namespace
urlpatterns = [
url(r"^$", views.HomePage.as_view(), name="home"),
url(r"^test/$", views.TestPage.as_view(), name="test"),
url(r"^thanks/$", views.ThanksPage.as_view(), name="thanks"),
url(r"^admin/", admin.site.urls),
url(r"^accounts/", include("accounts.urls", namespace="accounts")), #1
reference
url(r"^accounts/", include("django.contrib.auth.urls")), # 2
url(r"^posts/", include("posts.urls", namespace="posts")), # 3
url(r"^groups/",include("groups.urls",namespace="groups")),
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'bootstrap3',
'accounts',
'groups',
'posts',
Django v(2,2,6,'final',0) Python 3.7
请让我知道我是否在这里遗漏了什么,谢谢