Chris Hartjes wrote on 05/05/08 02:53: > I've been trying to do something that I *think* should be simple, > but apparently is not. Or, the more likely answer is that I am missing > something pretty obvious. I spent some time googling around for the answer > but didn't find what I was looking for. So here goes. > I'm building a web service to return sports game information. I have three > routes: > > / -- shows a help page on how to use the web service > /<team name>/<game date> > /<team name>/<start date>/<end date> > > <team name> is the name of a team in lowercase, could be 'yankees' or > 'red+sox' > the date fields are formatted as YYYY-MM-DD. Now, I've looked at both the > Django book and the online Django documentation to try and figure out the > correct way to get the routes to work. Here's what's in my urls.py file: > > from django.conf.urls.defaults import * > > urlpatterns = patterns('', > (r'^(?P<team>\w+)/(?P<game_date>\w+)/$', 'rallyhat.ws.views.team_by_date'), > (r'^(?P<team>\w+)/(?P<start_date>\w+)/(?P<end_date>\w+)/$', > 'rallyhat.ws.views.team_by_date_range'), > (r'^/?$', 'rallyhat.ws.views.index'), > ) > > Now, my index page route works just fine, but the two others won't work. > > When I try /yankees/2008-08-15 I get this: > > ***** > > Using the URLconf defined in rallyhat.urls, Django tried these URL patterns, > in this order: > > > 1. ^(?P<team>\w+)/(?P<game_date>\w+)/$ > > 2. ^(?P<team>\w+)/(?P<start_date>\w+)/(?P<end_date>\w+)/$ > > 3. ^/?$ > > > The current URL, /yankees/2008-05-18/, didn't match any of these. > ***** > > I *know* it's something dumb, but I just can't see it. Any help would be > greatly appreciated. >
Hi Chris \w matches [a-zA-Z0-9_] [1] The dashes there are not understood as dashes per se, but rather specify a range. I'd use either: (r'^(?P<team>\w+)/(?P<game_date>[^/]+)/$', 'myview'), or: (r'^(?P<team>\w+)/(?P<game_date>[\w-]+)/$', 'myview'), or, if you want it more specific: (r'^(?P<team>\w+)/(?P<game_date>\d{4}-\d{2}-\d{2})/$', 'myview'), Personally I'd go with the last example in this case. [1] http://docs.python.org/lib/re-syntax.html --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---