> Tried it...still no good

When in doubt, supply specifics, as in 'exactly what is the specific
URL you are trying to match?'

The given pattern matches an appropriate URL correctly. E.g.

>>> import re
>>> x = 'foobar_abcde/'
>>> m = re.match(r'^(?P<manufacturer>[a-zA-Z]+)_(?P<line>[a-zA-Z]+)/$', x)
>>> print m.groupdict()
{'line': 'abcde', 'manufacturer': 'foobar'}

I will observe, however, that \w in your original pattern also matches
0-9, so if you happen to be testing with numbers in either the
manufacturer or line portion of the URL, it ain't gonna work. It also
won't work if you are not supplying the trailing slash.

Going back to the original pattern, there is another way to write it.
If you change your pattern from:
      (r'^(?P<manufacturer>[\w-]+)_(?P<line>[\w-]+)/$', 'showline')
to:
      (r'^(?P<manufacturer>[\w-]+?)_(?P<line>[\w-]+?)/$', 'showline')
it will work as desired.

The '?' makes the '+' non-greedy, meaning it will grab as little as it
can and still successfully match. Thus, it won't consume the '_'
because that would cause failure.

If you are relatively new to regular expressions, I strongly recommend
perusing the Python re docs at http://docs.python.org/lib/module-re.html.
Read the section on syntax a few times (it can be subtle and deep),
construct some test patterns to play with, and make sure they match
(and don't match) as you would expect them to.

Out of curiosity, what do you mean when you say "so that all of my
pages are as close to the root as possible"? In a 'normal' web site,
the slashes actually indicate the directory hierarchy, but in Django
they mean ... whatever you want them to mean. Once you start having
fun with URL mapping, the whole concept of 'the root' largely goes
away. I now look at URLs as being procedure calls with optional
arguments.

  HTH,
  Peter
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to