AnswerBun.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!

Related Questions

Center a grouped bar chart in R (ggplot2)

2  Asked on December 20, 2021

   

Node js – public subfolder

1  Asked on December 20, 2021 by andres-darwin

 

Syntax error on getting multiple range VBA

0  Asked on December 20, 2021 by michael-norman

     

what can make my form not to see my input value

2  Asked on December 18, 2021 by michael-august

     

Regex Match/Wildcard

1  Asked on December 18, 2021 by ovenbakedpython

     

javascript async and await event listener: Pokemon

1  Asked on December 18, 2021 by jason-todd

   

Why do I want to use CRTP over simple template for static polymorphism?

2  Asked on December 18, 2021 by diveintoml

   

Check if string in path and do something

2  Asked on December 18, 2021

 

sql, delete duplicate records using an ID

2  Asked on December 18, 2021 by user12929912

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP