2017-05-22 112 views
1

我有这么长的url,我想匹配?之后的字符串,并在Class Based View的self.kwargs中使用它。 ?Django正则表达式匹配long url

new_timer/UID = 046F1572564080 &运行时间= 1102 &秒= 30stillrunning = 1个& numstoredtimes = 3个& storedtimes = 13:2-23:32-48:43 &校验= 71

我尝试以下它不工作。

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

我在做什么错?

+1

“的URLconf中搜索对所请求的URL,作为一个正常的Python字符串这不包括GET或POST参数或域名。名称。” https://docs.djangoproject.com/en/1.11/topics/http/urls/#what-the-urlconf-searches-against – kichik

回答

1

我在做什么错?

两个错误在您的正则表达式:^new_timer/(?P<params>[^/]+)/$

  1. 你不配套?可言。你也将不得不escape它。

  2. 最后您还有/。而URL中没有/结尾。

正确的正则表达式应该是:^new_timer/\?(?P<params>[^/]+)$

Regex101 Demo