TransWikia.com

no reverse matching at / and crawler is not a registered namespace

Stack Overflow Asked by SUDHEER RANJAN on December 22, 2020

I am trying to make a codeforces crawler and I am just adding user authentication in the somehow failed to implement. Reverse not match and crawler is not a registered namespace is the error I’m getting. I don’t know what files exactly are needed to put here so please ask me I will post them if you need it. I’m just a beginner and I need help.

crawler/urls.py

app_name = 'crawler'
urlpatterns = [
    path('',views.index,name='index'),
    path('formpage/',views.search_form_view , name='searchform'),
    path('formpage/<str:handle>',views.person, name= 'person'),
    path('user_login/',views.user_login,name ="user_login"),
    path('logout/',views.user_logout,name="logout"),
]

base.html

<body>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
  <!-- Brand -->
  <a class="navbar-brand" href="{% url 'crawler:index'%}">Crawler</a>
  <!-- Links -->
  <ul class="navbar-nav">
    <li class="nav-item">
      <a class="nav-link" href="{% url 'crawler:searchform'%}">Search</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Link 2</a>
    </li>
    {% if user.is_authenticated %}
     <li class="nav-item">
      <a class="nav-link" href="{%url 'crawler : logout'%}">Log Out</a>
    </li>
    {% else %}
     <li class="nav-item">
      <a class="nav-link" href="{%url 'crawler :user_login'%}">Login</a>
    {% endif %}
    </li>
    </li>
  </ul>
</nav>
<br>
{% block body_block %}
{% endblock %}
</body>

views.py

@login_required
def user_logout(request):
    logout(request)
    return HttpResponse(reverse('index'))

webcrawler/urls.py

app_name = 'crawler'
urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('crawler.urls',namespace= "crawler")),
]

One Answer

A two-part answer here.

No reverse match at /

The point is that, in both your main and app urls.py, you registered both URLs to be '', which means that there will be a match at (empty string) but won't be one at '/'. To fix this, simply add '/' to the main urls.py as it's a better practice.

Crawler is not a registered namespace

As you call an URL, it should be {% url 'crawler:index' %} or {% url 'crawler:searchform' %} or something because crawler is the main namespace but there are multiple URLs under it so you need to pass an additional parameter after your crawler namespace.

Answered by crimsonpython24 on December 22, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP