Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django Navbar No Reverse Match error – how do I fix this?

I’m receiving the below error when trying to link up my navbar in base.html in Django.

NoReverseMatch at /
‘home’ is not a registered namespace

I’m not sure why it’s not working, any help would be much appreciated!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

base.html:

          <ul class="nav navbar-nav ms-auto">
                                <li class="nav-item"><a class="nav-link text-white" href="{% url 'home:home' %}"><strong>Home</strong></a></li>
                                <li class="nav-item"><a class="nav-link text-white" href="{% url 'home' %}"><strong>My Health</strong></a></li>
                                <li class="nav-item"><a class="nav-link text-white" href="{% url 'login' %}"><strong>Login</strong></a></li>
                                <li class="nav-item"><a class="nav-link text-white" href="{% url 'signup' %}"><strong>Signup</strong></a></li>
                            </ul>

urls.py:

urlpatterns = [
    path('', views.home, name='home'),
    path('signup/', views.signup, name='signup'),
    path('login/', views.login, name='login'),
    path('favicon.ico', RedirectView.as_view(url=staticfiles_storage.url("favicon.ico"))),
    path('success/', views.success_view, name='success'),
]

views.py:

def home(request):
    return render(request, 'HealthHub/home.html')

>Solution :

In your urls.py you should modify this line:

 <li class="nav-item"><a class="nav-link text-white" href="{% url 'home' %}"><strong>Home</strong></a></li>

If you write home:home django looks for an app_name called home in your urls.py file.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading