Python 与#x27相反;帖子列表';没有找到';帖子列表';不是有效的视图函数或模式名称

Python 与#x27相反;帖子列表';没有找到';帖子列表';不是有效的视图函数或模式名称,python,django,Python,Django,我仍然处于学习Django的早期阶段,我刚刚遇到了这个错误(我正在学习一个教程,不太确定我把事情搞砸了!) “找不到'post list'的反向。post list'不是有效的视图函数或模式名称。” 在我的模板文件中,以下是我的模板标记的外观: {% if user.is_authenticated %} href="{% url 'post-list' %}" {% else %} 至于我的URL.py: urlpatterns = [ path

我仍然处于学习Django的早期阶段,我刚刚遇到了这个错误(我正在学习一个教程,不太确定我把事情搞砸了!)

“找不到'post list'的反向。post list'不是有效的视图函数或模式名称。”

在我的模板文件中,以下是我的模板标记的外观:

{% if user.is_authenticated %}
    href="{% url 'post-list' %}" 
    {% else %}
至于我的URL.py:

urlpatterns = [
    path('', PostListView.as_view(), name='post-list'),
    path('post/<int:pk>/', PostDetailView.as_view(), name='post-detail'),
    path('post/edit/<int:pk>/', PostEditView.as_view(), name='post-edit'),
    path('post/delete/<int:pk>/', PostDeleteView.as_view(), name='post-delete'),
    path('post/<int:post_pk>/comment/delete/<int:pk>/', CommentDeleteView.as_view(), name='comment-delete'),
    path('post/<int:post_pk>/comment/<int:pk>/like', AddCommentLike.as_view(), name='comment-like'),
    path('post/<int:post_pk>/comment/<int:pk>/dislike', AddCommentDislike.as_view(), name='comment-dislike'),
    path('post/<int:post_pk>/comment/<int:pk>/reply', CommentReplyView.as_view(), name='comment-reply'),
    path('post/<int:pk>/like', AddLike.as_view(), name='like'),
    path('post/<int:pk>/dislike', AddDislike.as_view(), name='dislike'),
    path('profile/<int:pk>/', ProfileView.as_view(), name='profile'),
    path('profile/edit/<int:pk>/', ProfileEditView.as_view(), name='profile-edit'),
    path('profile/<int:pk>/followers/', ListFollowers.as_view(), name='list-followers'),
    path('profile/<int:pk>/followers/add', AddFollower.as_view(), name='add-follower'),
    path('profile/<int:pk>/followers/remove', RemoveFollower.as_view(), name='remove-follower'),
    path('search/', UserSearch.as_view(), name='profile-search'),
    path('notification/<int:notification_pk>/post/<int:post_pk>', PostNotification.as_view(), name='post-notification'),
    path('notification/<int:notification_pk>/profile/<int:profile_pk>', FollowNotification.as_view(), name='follow-notification'),
    path('notification/<int:notification_pk>/thread/<int:object_pk>', ThreadNotification.as_view(), name='thread-notification'),
    path('notification/delete/<int:notification_pk>', RemoveNotification.as_view(), name='notification-delete'),
    path('inbox/', ListThreads.as_view(), name='inbox'),
    path('inbox/create-thread/', CreateThread.as_view(), name='create-thread'),
    path('inbox/<int:pk>/', ThreadView.as_view(), name='thread'),
    path('inbox/<int:pk>/create-message/', CreateMessage.as_view(), name='create-message'),
]
有人能给我点建议吗

谢谢,
Jay。

根据您的评论,您在
社交
模块的
url.py
中定义了路径。因此,从“根url”到触发
post list
视图的url之间没有路径,因此无法确定该视图名称的路径

您应该将其包括在内,例如:

urlpatterns = [
    path('admin/', admin.site.urls)
  , path('', include('core.urls'))
  , path('accounts/', include('allauth.urls'))
  , path('social/', include('social.urls'))
]
urlpatterns=[
路径('admin/',admin.site.url)
,路径(“”,include('core.url'))
,路径('accounts/',include('allauth.url'))
,路径('social/',包括('social.url'))

]
您是否在
URL.py
中指定了
应用程序名称
?嘿,威廉,非常感谢您的快速响应!:-)在URLs.py文件的顶部,我有以下代码:``` from django.URLs导入路径from.views导入PostListView、PostDetailView、PostEditView、PostDeleteView、CommentDeleteView、ProfileView、ProfileEditView、AddFollower、RemoveFollower、AddLike、AddUnlike、UserSearch、ListFollowers、AddCommentLike、AddCommentUnlike、,CommentReplyView、PostNotification、FollowNotification、ThreadNotification、RemoveNotification、CreateThread、ListThreads``但我还没有在其中包含我的实际应用程序名..请回答您的问题。对不起!我不确定如何在注释部分设置代码块的格式:)是否有一个地方包含了此处定义的
urlpatterns
?(可能是“root”
url.py
)?谢谢Willem!我现在要试试你的建议:-)这是教程-,教程只开发了一部分(16个教程),我认为课程的作者还在添加更多的教程,但他已经涵盖了启动和运行应用程序所需的大部分内容(我相信)-我只是在复习以前的课程,看看我是否遗漏了任何明显的内容)啊,是的,他引用了这个阶段(你在上面正确地提到了)(我在路径中添加了,但我仍然会遇到同样的错误!!
urlpatterns=[path('admin/',admin.site.url),path('',include('core.url')),path('accounts/',include('allauth.url')),path('social/',include('social.url')),]
@Jarjar95:你能用完整的回溯来回答你的问题吗?用回溯来编辑我的问题!谢谢!:)@Jarjar:但是你用
path('social/',include('social.url')添加了
social.url

"""socialnetwork URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('core.urls')),
    path('accounts/', include('allauth.urls')),
    path('social/', include('social.urls')),
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urlpatterns = [
    path('admin/', admin.site.urls)
  , path('', include('core.urls'))
  , path('accounts/', include('allauth.urls'))
  , path('social/', include('social.urls'))
]