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

249
Visualizações
Reverse for 'tagged' with arguments '('',)' not found. 1 pattern(s) tried: ['^tag/(?P<slug>[-\w]+)/$']

I keep getting this error message:

Reverse for 'tagged' with arguments '('',)' not found. 1 pattern(s) tried: ['\^tag/\(\?P(?P[^/]+)\[\-\\w\]\+\)/\$$']

when trying to load my base.html, because of an anchor tag. I have looked at other posts with the same issue, but I still don't know where I'm going wrong.

views.py

class TagIndexView(TagMixin, ListView):
    template_name = 'post/index.html'
    model = Post
    paginate_by = '10'
    context_object_name = 'posts'

    def get_queryset(self):
        return Post.objects.filter(tags__slug=self.kwargs.get('slug'))

def tagged(request):
    return render(request, 'blog/tagged.html', {'title': 'Tagged'})

urls.py

path(r'^tag/(?P<slug>[-\w]+)/$',TagIndexView.as_view, name='tagged')

base.html
The anchor tag:

<li class="list-group-item"><a href="{% url 'tagged' tag.slug %}">Tags</a></li>

But I keep getting a NoReverseMatch. In the anchor tag I have tried "tag.slug", "tag.id", "tag.pk" and some others.

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

0

  1. Use re_path() instead of path() for regular expressions.

    Reference: https://docs.djangoproject.com/en/3.2/topics/http/urls/#using-regular-expressions

  2. Use [-\w]* (0 or more) instead of [-\w]+ (1 or more) to allow empty string ('',).

  3. Call .as_view with .as_view() to create the view function.

#  path(r'^tag/(?P<slug>[-\w]+)/$', TagIndexView.as_view,   name='tagged')
re_path(r'^tag/(?P<slug>[-\w]*)/$', TagIndexView.as_view(), name='tagged')
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