NoReverseMatch error . Reverse for '...' not found

198 views Asked by At

I was trying to implement dynamic urls in Django when this occured

In my template.py, I added this line

 <a href="{% url 'Index' %}" role="button">Go to Index</a>

My urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path("admin/", admin.site.urls),
    path("", include("moviez.urls"))
]

My moviez.urls.py

from django.urls import path
from .views import IndexView

app_name = "moviez"

urlpatterns = [
    path("", IndexView, name="Index")
]

I think this should definitely should have work but it returned this error

NoReverseMatch at /
Reverse for 'Index' not found. 'Index' is not a valid view function or pattern name.

Can you please help me debug this?

Any help will be appreciated!

1

There are 1 answers

0
willeM_ Van Onsem On BEST ANSWER

Since you defined an app_name, you need to add this as prefix separated by a colon (:), so:

<a href="{% url 'moviez:Index' %}" role="button">Go to Index</a>

For more information, see the URL namespaces and included URLconfs section of the documentation.