Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

83
Visualizações
Dynamic link in Django always calls the first url path

In urls.py within urlpatterns I have below two lines

urlspatterns = [
...
path('<slug:productSlug>', ProductView.as_view(), name = 'viewProduct'),
path('<slug:boxSlug>', BoxView.as_view(), name = 'BoxView'),
...
]

In my html template I have two links

<a href="{% url 'viewProduct' item.productSlug %}" class="btn btn-outline-primary" tabindex="-1" role="button" aria-disabled="true">product view</a>

<a href="{% url 'BoxView' item.boxSlug %}" class="btn btn-outline-primary" tabindex="-1" role="button" aria-disabled="true">Box View</a>

The problem is even though I specified BoxView in the {% url 'BoxView' ... %} it keeps calling the viewProduct path. If I reverse the order of the two paths in urlPatterns then, it keeps calling the 'BoxView'. What I don't understand is it keeps calling whatever it finds first in urlPatterns.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You something to distingish between the view type. For example you could:

urlspatterns = [
...
path('product_view/<slug:productSlug>', ProductView.as_view(), name = 'viewProduct'),
path('box_view/<slug:boxSlug>', BoxView.as_view(), name = 'BoxView'),
...
]
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda