Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

414
Vistas
NoReverseMatch at "/"

Hello I get an error "NoReverseMatch at "/" It occurs when i change in HTML template to {% url 'cart-page' cart.id %}, when i use user.username everything works but I would like to have a cart.id instead username. It is not fault of urls.py because i have changed int to str , and vice versa.

code:

HTML:

<div class="navbar__rightside">
            <a class="navbar__link" href="{% url 'cart-page' cart.id %}">Cart</a>
            <a class= "navbar__link" href="{% url 'profile-page' user.username %}">Profile</a>
            <a class="navbar__link" href="{% url 'logout-page' %}">Logout</a>
        </div>

views.py:

class ShopListView(ListView):
    model = Item
    template_name =  'shop/home.html'
    context_object_name = 'items'
    def post(self, request, *args, **kwargs):
        return reverse('detail-page')

class CartView(TemplateView):
 template_name = "shop/cart.html"
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['cart'] = Cart.objects.annotate(
        price=Sum(F('orderitem__item__price') * F('orderitem__quantity'))
        ).get(order_user= self.request.user)
        cart = context['cart']
        cart.total = cart.price
        cart.save()
        context['order_items'] = OrderItem.objects.filter(cart=cart)
        return context
    def post(self, request, pk):
        if 'minus' in request.POST:
            cart = Cart.objects.get(order_user=self.request.user)
            OrderItem.objects.filter(id=pk, cart=cart).update(
            quantity=F('quantity')-1)
            return HttpResponse("cart uptaded")

urls.py

    path('', ShopListView.as_view(), name='home-page'),
    path('cart/<int:pk>/', CartView.as_view(), name='cart-page'),
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

in your html

<div class="navbar__rightside">
            <a class="navbar__link" href="{% url 'cart-page' pk=cart.id %}">Cart</a>
            <a class= "navbar__link" href="{% url 'profile-page' user.username %}">Profile</a>
            <a class="navbar__link" href="{% url 'logout-page' %}">Logout</a>
        </div>

you have to tell what is id you are referring to and tell me if still does not work for you

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda