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

125
Views
cómo usar get_absolute_url

Tengo problemas para entender el código del sitio web en el tutorial. lo que entendí es que urls.py toma un argumento como product_slug que se usa para obtener un objeto en mi vista show_product y otro argumento se usa como template_name pero lo que hace el argumento 'catalog_product' está definido en mi modelo. cuando elimino ' catalog_product' me sale un error como:

sin coincidencia inversa en /categoría/guitarra

explique cómo funciona este argumento get_absolute_url y cómo y dónde puedo usarlo.

modelo.py es:

 def get_absolute_url(self): return reverse('catalog_product', (), { 'product_slug': self.slug })

Estoy teniendo uurls.py como:

 url(r'^product/(?P<product_slug>[-\w]+)/$',show_product, {'template_name':'catalog/product.html'}, 'catalog_product')

y vistas.py:

 def show_product(request, product_slug, template_name="catalog/product.html"): p = get_object_or_404(Product, slug=product_slug) categories = p.categories.filter(is_active=True) page_title = p.name meta_keywords = p.meta_keywords meta_description = p.meta_description return render(request, template_name, locals())

plantilla producto.html :-

 % extends "catalog.html" %} {% block content %} <div class="product_image" > {% load static %} <img src="{% static 'images/products/main/{{ p.image}}' %}" alt="{{ p.name }}" /> </div> <h1>{{ p.name }}</h1> Brand: <em>{{ p.brand }}</em> <br /><br /> SKU: {{ p.sku }} <br /> In categor{{ categories.count|pluralize:"y,ies" }}: {% for c in categories %} <a href="{{ c.get_absolute_url }}">{{ c.name }}</a> {% if not forloop.last %}, {% endif %} {% endfor %} <br /><br /> {% if p.sale_price %} Was: <del>$ {{ p.old_price }}</del> <br /> Now: $ {{ p.price }} {% else %} Price: $ {{ p.price }} {% endif %} <br /><br /> [add to cart button] <br /><br /> <div class="cb"><br /><br /></div> <h3>Product Description</h3> {{ p.description }} {% endblock %}
over 4 years ago · Santiago Trujillo
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!