Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

394
Views
Sin coincidencia inversa en "/"

Hola, recibo un error "NoReverseMatch at "/" Ocurre cuando cambio la plantilla HTML a {% url 'cart-page' cart.id %}, cuando uso user.username todo funciona pero me gustaría tener un carrito .id en lugar de nombre de usuario No es culpa de urls.py porque he cambiado int a str , y viceversa.

código:

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>

vistas.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 answers
Answer question

0

en tu 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>

tienes que decir a que id te refieres y decirme si todavia no te funciona

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!