不是有效的正则表达式

时间:2019-08-13 01:56:58

标签: python regex django

我不明白为什么会出现此错误:

django.core.exceptions.ImproperlyConfigured:"^customers/(?P<pk>[0-9]+)$" is not a valid regular expression: unknown extension ?P& at position 12

这是我的urls.py文件代码

from django.conf.urls import url 
from customers import views 

urlpatterns = [ 

  url(r'^customers/$', views.customer_list),
  url(r'^customers/(?P<pk>[0-9]+)$', views.customer_detail),
  url(r'^customers/age/(?P<age>[0-9]+)/$', views.customer_list_age),

]

1 个答案:

答案 0 :(得分:1)

您需要指定df1 <- df %>% group_by(group = data.table::rleid(var1 > 4), group1 = cumsum(ts - lag(ts, default = first(ts)) > 3600)) %>% mutate(temp = row_number() * (var1 <= 4)) %>% ungroup() %>% filter(var1 <= 4) %>% select(ts, var1, temp) df2 <- df1 %>% mutate(temp2 = ifelse(temp==1, 1, 0), newgroup = cumsum(temp2)) df3 <- df2 %>% group_by(newgroup) %>% slice(which.max(temp)) mean(df3$temp) # example dataframe with desired output columns to then get actual output df <- structure(list(ts = structure(c(-2208967200, -2208963600, -2208960000, -2208956400, -2208952800, -2208949200, -2208945600, -2208942000, -2208938400, -2208934800, -2208931200, -2208927600, -2208924000, -2208913200, -2208909600, -2208906000, -2208902400, -2208898800, -2208895200, -2208891600, -2208888000, -2208884400, -2208880800, -2208877200, -2208852000, -2208848400, -2208844800, -2208841200, -2208837600, -2208834000, -2208830400, -2208826800, -2208823200, -2208819600, -2208816000, -2208812400, -2208808800, -2208805200, -2208801600), class = c("POSIXct", "POSIXt"), tzone = ""), var1 = c(1L, 3L, 4L, 5L, 4L, 3L, 5L, 6L, 7L, 8L, 3L, 2L, 2L, 2L, 3L, 3L, 2L, 2L, 1L, 1L, 1L, 1L, 4L, 4L, 3L, 9L, 3L, 3L, 3L, 2L, 2L, 3L, 4L, 5L, 3L, 2L, 1L, 2L, 3L), HoursBelow5 = c(1L, 2L, 3L, 0L, 1L, 2L, 0L, 0L, 0L, 0L, 1L, 2L, 3L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 1L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 0L, 1L, 2L, 3L, 4L, 5L), RunningGroup = c(1L, 1L, 1L, 2L, 3L, 3L, 4L, 5L, 6L, 7L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 14L, 14L, 14L, 14L, 14L), NotContinuous = c("", "", "", "", "", "", "", "", "", "", "", "", "", "NC", "", "", "", "", "", "", "", "", "", "", "NC", "", "", "", "", "", "", "", "", "", "", "", "", "", "")), row.names = c(NA, -39L), class = "data.frame") 而不是<符号,并且对于&lt;,它也应该是&gt;(不要对网址格式进行HTML转义),因为{ {1}}是指一个命名的捕获组。即。命名捕获组中与模式匹配的所有字符都将通过匹配对象上的名称进行访问。

>

因此,在这里,您可以通过访问视图kwargs来获取视图pk。 (?P<name>pattern)

DEMO