[英]Django no reverse match on heroku
I am getting NoReverseMatch at /post/1/ Reverse for 'blog_home' not found. 'blog_home' is not a valid view function or pattern name.
我
NoReverseMatch at /post/1/ Reverse for 'blog_home' not found. 'blog_home' is not a valid view function or pattern name.
NoReverseMatch at /post/1/ Reverse for 'blog_home' not found. 'blog_home' is not a valid view function or pattern name.
this error on my Django website hosted on Heroku, but the code works fine when I host the website locally.我在 Heroku 上托管的 Django 网站上出现此错误,但当我在本地托管该网站时,代码工作正常。 I think that it has something to do with Heroku. My urls.py
我认为它与 Heroku 有关。我的 urls.py
urlpatterns = [
path('', PostListView.as_view(), name='blog-home'),
path('post/<int:pk>/', PostDetailView.as_view(), name='post-detail')
]
views.py: https://controlc.com/fd518ea0 (link because stack overflow said too much code) views.py: https://controlc.com/fd518ea0 (链接是因为stack overflow说代码太多)
Error:错误:
Environment:
Request Method: GET
Request URL: http://<appname>.herokuapp.com/post/1/
Django Version: 2.2.1
Python Version: 3.9.0
Template error:
In template /app/django_web_app/blog/templates/blog/base.html, error at line 0
Reverse for 'blog_home' not found. 'blog_home' is not a valid view function or pattern name.
1 : {% load staticfiles %}
2 : <!doctype html>
3 : <html lang="en">
4 : <head>
5 :
6 : <!-- Required meta tags -->
7 : <meta charset="utf-8">
8 : <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
9 :
10 :
Exception Type: NoReverseMatch at /post/1/
Exception Value: Reverse for 'blog_home' not found. 'blog_home' is not a valid view function or pattern name.
Python version: 3.9 Python 版本:3.9
Django version: 2.2.1 Django 版本:2.2.1
In urls.py, blog-home
is hyphenated.在 urls.py 中,
blog-home
是带连字符的。 The failing code is attempting to reverse blog_home
(with an underscore), which does not match.失败的代码试图反转不匹配的
blog_home
(带下划线)。 Change one or the other so they match.改变一个或另一个使它们匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.