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

347
Views
Why is my django url regex not working

I want my url to accept 0 or more digits(positive or negative integers), I mean it should match '/','/0',...,'/9' as well as '/-9','/-88' etc.

This is the regex I am using ^([-]?[0-9]*)/$ . It works for all urls except '/', what is the problem with this regex?

EDIT:

This is my urlpatterns in urls.py in project directory:

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'',include('basecalendar.urls'), name='date'),
]

and this is urlpattern for basecalendar

urlpatterns=[
    url(r'^([-]?[0-9]*)/$',views.get_date),
]
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Since you are working with urls you might want to make sure that you are ending your url with '/'. Also, the reason why this is not working because your url is expecting a '/' at the end. So a url something/ does not match your regex, rather something// does. All these observations are being made according to your regex. Usually to handle such conditions you should add one more url above your previous regex, something like:

url(r'^something/$', view),
url(r'^something/([-]?[0-9]*)/$', view),
about 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!