Django - Reverse for '' not found. '' is not a valid view function or pattern name
When you use the url tag you should use quotes for string literals, for example:
{% url 'products' %}
At the moment product
is treated like a variable and evaluates to ''
in the error message.
- The syntax for specifying url is
{% url namespace:url_name %}
. So, check if you have added theapp_name
in urls.py. - In my case, I had misspelled the url_name. The urls.py had the following content
path('<int:question_id>/', views.detail, name='question_detail')
whereas the index.html file had the following entry<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
. Notice the incorrect name.
I was receiving the same error when not specifying the app
name before pattern name.
In my case:
app-name
: Blog
pattern-name
: post-delete
reverse_lazy('Blog:post-delete')
worked.