wisemukiga wisemukiga -4 years ago 168
Python Question

Django Regex matching long url

I have this long url and I want to match the string after

and have it available in self.kwargs of Class Based View.


I tried the following and it's not working.

Urlpatterns = [
# bunch of awesome urls

What am I doing wrong?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download