Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

255
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda