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

251
Views
Cómo escapar '/' en las URL de Django

Estoy trabajando en un proyecto que genera direcciones URL dinámicas, por ejemplo, si escribes mysite.com/<yourtexthere> El sitio debe generar una URL con mysite.com/yourtextthere (donde yourtext here es un slug de un modelo) y puedo haz eso, pero el problema surge cuando pongo algo como mysite.com/yourtextthere/moretext , Django no coincide con ninguno de mis patrones de URL existentes y me da 404.

Quería preguntar si hay alguna manera de tratar '/' como un carácter más y generar una url única mymysite.com/yourtextthere/moretext donde yourtextthere/moretext es ahora el slug.

vistas.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 answers
Answer question

0

De los documentos de modelos de Django:

Un slug es una etiqueta corta para algo, que contiene solo letras, números, guiones bajos o guiones.

Entonces, el 404 es realmente correcto, tal vez use otro campo.

over 4 years ago · Santiago Trujillo Report
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!