On Wed, 2008-11-26 at 17:54 -0800, Dylan Lorimer wrote: > Hi, > > So I'm trying to model my URLs for a blog I'm building on Django using > the following structure: > > http://www.myblog.com/tags/tag1/tag2/tag3/tag4/etc etc > > The idea being that after the initial /tags/ you can add on any tag > and it would act as a filter against the blog entries. I'm trying to > follow the principle of "hackable urls" that I've read about. > > My trouble is that I'm not sure how to structure the urls.py entry. I > figure I need something like: > > If I wanted only the first element after the /tags I could use this: > > (r'^tags/(?P<tag_name>\w+)/$','view_function_name'), > > But since I want N elements after the /tags, I'm thinking I need > something like this: > > (r'^tags/{(?P<tag_name>\w+)/$}+','view_function_name'),
You can't use '+' (or '*') in a regular expression to capture the same group multiple times. Only the last occurrence is matched. So there are a few comments I would make here. First off, your initial choice isn't too bad if you view it as "tag_names" and capture "[\w/]+". Your view will be passed a string that you can split on '/' to get a list of tag names. The second comment is that you might want to consider your URL design a bit more. You are really saying that none of the tag names are any more special or highly prioritised than any of the others. Although what you haven't isn't "wrong" at all, it is conventional that '/' implies some kind of hierarchy. Yet tag1/tag2 and tag2/tag1 are the same in your scheme. So you may want to use something like a comma to separate the components there, indicating that the ordering isn't important (the comma suggestion comes from the Richardson & Ruby book, "RESTful Web Services", where they suggest using a semicolon for ordered information and a comma for unordered information, where, in both cases, neither piece of information is subordinate to the other one. However you design your URLs, you'll still want to go down the first path: capture the entire variable portion in one blob and then split it on the separate in your view. Regards Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---