1

I have this long url and I want to match the string after ? and have it available in self.kwargs of Class Based View.

new_timer/?UID=046F1572564080&runtime=1102&seconds=30stillrunning=1&numstoredtimes=3&storedtimes=13:2-23:32-48:43&checksum=71

I tried the following and it's not working.

Urlpatterns = [
    # bunch of awesome urls
    url(r'^new_timer/(?P<params>[^/]+)/$',NewTimerView.as_view(),
        name='new_timer'),
]

What am I doing wrong?

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
willyhakim
  • 327
  • 4
  • 11
  • 1
    "The URLconf searches against the requested URL, as a normal Python string. This does not include GET or POST parameters, or the domain name." https://docs.djangoproject.com/en/1.11/topics/http/urls/#what-the-urlconf-searches-against – kichik May 22 '17 at 19:49

1 Answers1

1

What am I doing wrong?

Two mistakes in your regex: ^new_timer/(?P<params>[^/]+)/$

  1. You are not matching ? at all. Also you will have to escape it.

  2. You have / in end. Whereas there is no / in URL at end.

Correct regex should be: ^new_timer/\?(?P<params>[^/]+)$

Regex101 Demo

Rahul
  • 2,658
  • 12
  • 28