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

263
Visualizações
How to escape '/' in django urls

I am working on a project that generates dynamic urls for eg if you type mysite.com/<yourtexthere> The site should generate a url with mysite.com/yourtexthere (where yourtext here is a slug of a model)and I am able to do that but the problem arises when I put something like this mysite.com/yourtexthere/moretext, Django doesn't match it with any of my existing URL patterns and gives me 404.

I wanted to ask is there a way by which I can treat '/' as just another character and generate unique url mymysite.com/yourtexthere/moretext where yourtexthere/moretext is now the slug.

views.py

def textview(request, slug):
    obj, created= Text.objects.get_or_create(slug=slug, defaults={'text':'', 'password':'123'})
    return render(request, 'text/textpage.html', {'obj' : obj, 'created' : created})

urls.py

# Only patterns
urlpatterns = [
    path('', home, name='home'),
    path('<slug:slug>/', textview, name='textview'),
]
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

From Django models docs:

A slug is a short label for something, containing only letters, numbers, underscores or hyphens.

So the 404 is actually correct, maybe use another field.

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