3

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),
]
2
  • 1
    post the contents of urls.py file. May be you have assigned another view for / url. Commented Apr 18, 2017 at 10:53
  • @AvinashRaj I have added the necessary details Commented Apr 18, 2017 at 11:25

1 Answer 1

1

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),
Sign up to request clarification or add additional context in comments.

2 Comments

Removing / from my current regex worked with my urlconf, now / points to '/0'
No answer for me in this text

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.