So, suppose I have a django app which needs to respond to a url like this: http://127.0.0.1:8000/food%20log/4/up/ . The original parameter is “food log”, but it needed to have the space replaced with %20 when it was included in the url. Now the link has been clicked on, and it’s coming back to urls.py.
urlpatterns = patterns('',
(r'^(?P<content_type>\w+)/(?P<object_id>\d+)/(?P<direction>up|down|clear)/$', process_vote),
…
)
So, it appears that it is not able to properly recognize the parameter . This is functional code prior to wanting to use a content_type which has a space in it. If we assume for the moment that I can’t just remove the space from the name of that content_type throughout the rest of the system, how do I get the urlpatterns function to recognize that “food%20log” is actually “food log”, so that it will recognize it as a valid ?
Basically I want to preprocess the string before it’s acted on by urlpatterns, but I am not sure how/where to do that. Thanks for any assistance.
According to the Python manual for the re module:
So maybe include the space in the regular expression in addition to \w.