Noreversematch in Django

Asked

Viewed 59 times

0

Hello I have a problem in Django that cannot solve a url with parameter (Django.urls.exceptions.Noreversematch: Reverse for 'incluNaRota' with Arguments '(',)' not found. 1 Pattern(s) tried: ['home/include/(? P[^/]+)/$']). I’ve looked here in Stack but similar problems do not solve mine.

Follow the codes of.py urls, views.py and template:

path('remover/<str:idCliente>/', views.removerDaRota, name='removerDaRota'),
path('incluir/<str:idCliente>/', views.incluirNaRota, name='incluirNaRota'),


def removerDaRota(request, idCliente):
    cliente = Auxiliar.objetos.filter(codigo=idCliente).first()
    cliente.incluido = False
    cliente.save()
    clientesIncluidos, clientesNaoIncluidos = getIncluidosENaoIncluidos()
    return render(request, 'nm/rotas/confirmar.html', {'clientesIncluidos': clientesIncluidos, 'clientesNaoIncluidos': clientesNaoIncluidos})


def incluirNaRota(request, idCliente):
    cliente = Auxiliar.objetos.filter(codigo=idCliente).first()
    cliente.incluido = True
    cliente.save()
    clientesIncluidos, clientesNaoIncluidos = getIncluidosENaoIncluidos()
    return render(request, 'nm/rotas/confirmar.html', {'clientesAleatorios': clientesIncluidos, 'clientesNaoIncluidos': clientesNaoIncluidos})

    {% for cliente in clientesIncluidos%}
    <li>{{cliente.codigo}} {{cliente.razao}} <a href="{% url 'nm:removerDaRota' cliente.codigo %}">Remover</a>
    <li>{{cliente.codigo}} {{cliente.razao}} <a href="{% url 'nm:incluirNaRota' cliente.codigo %}">Incluir na rota</a></li>
  • In your.py urls, it should be an integer, path('<int:pk>/delete/', views.removerDaRota, name='removerDaRota').. the values will be recovered by the number and not by a literal. Then change there to see, if you have error put the result.

  • I’ve changed, you haven’t solved :(

  • could explain these two functions remove Ota and include Ota? , would be to remove an item in the bank!!! Maybe I can help you if I talk about these functions. Because I may have misinterpreted this warning from Django.

  • Have you tried instead of surrender return render(request, 'nm/rotas/confirmar.html use the redirect? Probably gonna make another mistake, but I think you’ll be able to fix it

  • Realize that the mistake Reverse for 'incluirNaRota' with arguments '('',)' shows that the argument is a tuple with empty string for the first element. Thus, its url would be translated to http://seu.dominio/incluir/ and this cannot be found in your.py urls, as it expects a string after the incluir/. Since I’m not seeing all the code, I can’t tell if you’re passing an empty list from your view or if the problem is in the template.

  • @Paulomarques understood, I managed to solve, thank you all

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.