Noreversematch at /view_clients/

Asked

Viewed 207 times

0

I want to print out a simple customer sheet inside a list of customers I’ve registered in the app. When I click on the link to generate me returns this error:

Noreversematch at /view_clients/

Reverse for 'client' with Arguments '(',)' not found. 1 Pattern(s) tried: ['view_clients /client_id :id$']

py urls of the project:

from django.contrib import admin
from django.urls import include, path
app_name = 'app_web_gym'

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

py urls of the application:

from django.urls import path
from . import views

app_name = 'app_web_gym'

urlpatterns = [
    path('', views.index, name='index'),
    path('view_clients/', views.clientes, name='clientes'),
    path('view_clients/client_id:id', views.cliente, name='cliente'),

]

py views.:

from django.shortcuts import render
from .models import Cliente

def index(request):
    """A página inicial de Web Gym"""
    return render(request, 'app_web_gym/index.html')

def clientes(request):
    clientes = Cliente.objects.order_by('date_added')
    context = {'clientes': clientes}
    return render(request, 'app_web_gym/view_clients.html', context)

def cliente(request, client_id):
    cliente = Cliente.objects.get(id=client_id)
    last_name = cliente.last_name
    context = {'cliente': cliente, 'last_name': last_name}
    return render (request, 'app_web_gym/cliente.html', context)

html base.:

<p>
    <a href="{% url 'app_web_gym:index' %}">Web Gym</a>
    <a href="{% url 'app_web_gym:clientes' %}">Clientes</a>
</p>

{% block content %} {% endblock content %}

view_clients.html:

{% extends 'app_web_gym/base.html' %}

{% block content %}
    <p>Clientes</p>
    <ul>
        {% for cli in clientes %}
            <li>
                <a href="{% url 'app_web_gym:cliente' cli.id %}">{{cli}}</a>
            </li>
        {% empty %}
            <li>Nenhum cliente para mostrar.</li>
        {% endfor %}
    </ul>

{% endblock content %}

html clients.:

{% extends 'app_web_gym/base.html' %}

{% block content %}
    <p>Cliente</p>
    <p>{{cliente}} {{last_name}}</p>


{% endblock content %}

Sorry for any mistake. I’m starting in Jango.

1 answer

1


Two things to change:

In your urlpatterns you must correct to:

urlpatterns = [
    path('', views.index, name='index'),
    path('view_clients/', views.clientes, name='clientes'),
    path('view_clients/&ltint:client_id>/', views.cliente, name='cliente'),

]

And in the template for:

&lta href="{% url 'app_web_gym:cliente' client_id=cli.id %}">{{cli}}</a>

Browser other questions tagged

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