开发者社区> 问答> 正文

包括URLconf的simplesocial。url '似乎没有任何模式。…圆形进口

无法找到上述错误的来源:我已经审查了下面的链接,提供的解决方案没有解决我的问题:Django -循环模型导入问题 以下url似乎会导致出现循环导入错误。当注释掉时,错误不会出现。 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"),

]

组/ 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"),

]

职位/ 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/url .py文件中的以下3行代码时。 返回以下错误: NoReverseMatch在/ “accounts”不是注册的名称空间

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',

姜戈五世(2,2,6,《最终》,0) 蟒蛇3.7 如果我遗漏了什么,请告诉我,谢谢 问题来源StackOverflow 地址:/questions/59385145/the-included-urlconf-simplesocial-urls-does-not-appear-to-have-any-patterns-in

展开
收起
kun坤 2019-12-26 10:48:17 387 0
0 条回答
写回答
取消 提交回答
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载