I have a problem I cant seem to figure out. Working in Django trying to get a hanlde on the URL matching . I have one that works. One that doesnt and I cannot figure out why. Hoping someone can help.
The one that works:
url(r'^person/device/program/oneday/(?P<meter_id>\d+)/$', 
therm_control.Get_One_Day_Of_Current_Device_Schedule.as_view(), 
name="one-day-url"),
When I use this url:
http://127.0.0.1:8000/personview/person/device/program/oneday/149778/
The one that does not:
url(r'^person/device/program/oneday/(?P<meter_id>\d+)/(?P<day_of_the_week>\s+)/$', 
therm_control.Get_One_Day_Of_Current_Thermostat_Schedule.as_view(), 
name="one-day-url"),
When I use this url:
http://127.0.0.1:8000/personview/person/device/program/oneday/149778/Monday/
They view is the same in both cases. For trying the second I add the day_of_the_week to the def get()
What I see in the debug is the 404:
Request Method:     GET
Request URL:    http://127.0.0.1:8000/personview/person/device/program/oneday/149778/Monday/
I see this in the URLconf list so I know it is in the conf:
^personview/ ^person/device/program/oneday/(?P<meter_id>\d+)/(?P<day_of_the_week>\s+)/$ [name='one-day-url'] 
Any help is greatly appreciated.
The problem is that \s means a whitespace character in a regex, so in your URLconf the day of the week has to be a sequence of whitespace characters. If you replace \s with \w it will instead look for word characters, which is what you want.
\s+ will match one or more spaces, you want \w+:
url(r'^person/device/program/oneday/(?P<meter_id>\d+)/(?P<day_of_the_week>\w+)/$', 
    therm_control.Get_One_Day_Of_Current_Thermostat_Schedule.as_view(),
    name="one-day-url"),
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论