-1

I'm trying to generate a regex for just numbers. But for some reason the pattern doesn't seem to match. My code is:

url('^[\d\-]+/$', views.room, name='room'),

The request has to go to this expression. The HTML href for the above is:

<href="/polls/layout/103/>
  • 5
    Possible duplicate of [Django URL Pattern For Integer](http://stackoverflow.com/questions/23420655/django-url-pattern-for-integer) – Wasi Ahmad Dec 13 '16 at 01:50

1 Answers1

2

I'm assuming polls/ is caught upstream in the project urls.py and you're editing the app urls.py. You need to catch 'layout/' as well as '103'.

url('^layout/[0-9]+/$', views.room, name='room'),

If you need to capture the '103' for further processing within the view (likely), you might want to try something like:

url('^layout/(?P<room_number>[0-9]+)/$', views.room, name='room'),

where 'room_number' is an arg to the room class in your app's views.py.

Tim Bowden
  • 106
  • 7