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

262
Views
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 answers
Answer question

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 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!