Knight_Crawler
Knight_Crawler

Reputation: 13

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. this error on my Django website hosted on Heroku, but the code works fine when I host the website locally. I think that it has something to do with Heroku. My 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)

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

Django version: 2.2.1

Upvotes: 0

Views: 60

Answers (1)

dr_rompecabezas
dr_rompecabezas

Reputation: 61

In urls.py, blog-home is hyphenated. The failing code is attempting to reverse blog_home (with an underscore), which does not match. Change one or the other so they match.

Upvotes: 1

Related Questions