django 找不到“PostDetail”的反转,“PostDetail”不是有效的视图函数或模式名称

xjreopfe  于 2023-02-17  发布在  Go
关注(0)|答案(1)|浏览(122)

我有两种不同的看法:一个用于呈现帖子,另一个用于呈现帖子中的评论。当我试图从评论视图重定向帖子视图时,我得到了一个错误

> NoReverseMatch at /3/create Reverse for 'PostDetail' not found.
> 'PostDetail' is not a valid view function or pattern name. Request
> Method:   POST Request URL:   http://localhost:8000/3/create Django
> Version:  4.1.2 Exception Type:   NoReverseMatch Exception Value: 
> Reverse for 'PostDetail' not found. 'PostDetail' is not a valid view
> function or pattern name. Exception
> Location: /workspace/.pip-modules/lib/python3.8/site-packages/django/urls/resolvers.py,
> line 828, in _reverse_with_prefix Raised
> during:   website.views.createComment Python
> Executable:   /home/gitpod/.pyenv/versions/3.8.11/bin/python3 Python
> Version:  3.8.11 Python Path:  ['/workspace/RaizalDuo', 
> '/home/gitpod/.pyenv/versions/3.8.11/lib/python38.zip', 
> '/home/gitpod/.pyenv/versions/3.8.11/lib/python3.8', 
> '/home/gitpod/.pyenv/versions/3.8.11/lib/python3.8/lib-dynload', 
> '/workspace/.pip-modules/lib/python3.8/site-packages', 
> '/home/gitpod/.pyenv/versions/3.8.11/lib/python3.8/site-packages']
> Server time:  Sun, 12 Feb 2023 07:55:21 +0000 Traceback Switch to
> copy-and-paste view
> /workspace/.pip-modules/lib/python3.8/site-packages/django/core/handlers/exception.py,
> line 55, in inner
>                 response = get_response(request) … Local vars /workspace/.pip-modules/lib/python3.8/site-packages/django/core/handlers/base.py,
> line 197, in _get_response
>                 response = wrapped_callback(request, *callback_args, **callback_kwargs) … Local vars /workspace/.pip-modules/lib/python3.8/site-packages/django/contrib/auth/decorators.py,
> line 23, in _wrapped_view
>                 return view_func(request, *args, **kwargs) … Local vars /workspace/RaizalDuo/website/views.py, line 51, in createComment
>             return redirect('PostDetail', newComment.post.id

我正在尝试查看post_details. html中的评论

72qzrwbm

72qzrwbm1#

网址:
从. import视图从django.urls导入路径,包括从django.conf导入设置
网址模式=[

path('', views.PostList.as_view(), name='home'),
path('<int:post_id>', views.PostDetail, name='post_detail'),
path('PostDetails', views.PostDetail, name='post_detail'),
path('like/<int:id>/', views.PostLike, name='post_like'),  
path("<int:post_id>/create", views.createComment, name="createComment"),
path("comment/<int:comment_id>", views.updatecomment, name="updatecomment"),

]

相关问题