Reverse for 'save-review' not found. 'save-review' is not a valid view function or pattern name

I have error in Django: "django.urls.exceptions.NoReverseMatch: Reverse for ‘save-review’ not found. ‘save-review’ is not a valid view function or pattern name."

I study django through YouTube, I do everything as in the video, but I get an error. When there is no authorization and "Add review" button is hidden, the page works fine. But when "Add review" button is shown, the product page doesn’t load and throws an error.


<div class="col-md-6">
            <h3 class="my-3">Обзоры - 4.5/5 <i class="fa fa-star text-warning"></i>
                {% if user.is_authenticated %}
                <button type="button" data-toggle="modal" data-target="#productReview" 
                class="btn btn-warning bt-sm float-right">Add review</button>
                {% endif %}
            <div class="card">
                <div class="card-body" style="max-height: 400px; overflow; auto;">
                    <!-- Detail -->
                    <blockquote class="blockquote text-right">
                        <small>Good product</small>
                            <footer class="blockquote-footer">John Lenon
                                <cite title="Source Title">
                                    <i class="fa fa-star text-warning"></i>
                                    <i class="fa fa-star text-warning"></i>
                                    <i class="fa fa-star text-warning"></i>
                                    <i class="fa fa-star text-warning"></i>
{% if user.is_authenticated %}
        <!-- Product Review -->
        <div class="modal fade" id="productReview" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Product Review</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
              <div class="modal-body">
                  <form id="addForm" method="post" id="addForm" action="{% url 'save-review' %}">
                      {% csrf_token %}
                      <table class="table table-bordered">
                              <td colspan="2">
                                  <button type="submit" class="btn btn-primary">Submit</button>
                                  <input type="reset" value="Reset" id="reset" />
                      <p class="ajaxRes"></p>
        <!-- Product Review End -->
        {% endif %}

from django.urls import path, include
from . import views
from django.conf import settings
from django.conf.urls.static import static

    path('', views.home, name='home'),
    path('product-list', views.product_list, name='product-list'),    
    path('checkout', views.checkout, name='checkout'),
    path('save-review/<int:pid>', views.save_review, name='save_review'),

def save_review(request, pid):
    product = Product.objects.get(pk=pid)
    user = request.user
    review = ProductReview.objects.create(
    return JsonResponse({'bool': True})


                    $(".ajaxRes").html('Data has been added.');

When I insert action="#" instead of action="{% url 'save-review' %}", the error disappears. Tried changing path in, didn’t help either. Tried solutions from SO. Cleared cache, rebooted PC. I understand that python doesn’t understand what to do with ‘save-review’, but why? The video has been on YouTube for a year, maybe something has changed in the syntax?

>Solution :

Your URL is named save_review, but you have written {% url 'save-review' %} in your HTML.

Replace by {% url 'save_review' %} for making your code work.

Leave a Reply