On Aug 27, 2007, at 10:42 AM, Neil Blakey-Milner wrote:
I'd use it. I've run into this problem twice (and totally forgot how I solved it the first time), and I've had one of my developer colleagues come to me with the same problem as well. We almost exclusively use named routes - I think there's only one place in the two projects we've done with Routes where we don't - and so the current behaviour feels a bit weird.
Okey doke! It's now in the Routes trunk. Just set mapper.hardcode_names = True, and using named routes will restrict URL generation to only the route with the name. Example:
>>> from routes import * >>> m = Mapper()>>> m.connect('gallery_thumb', 'images/gallery/:(image_id) _thumbnail.jpg')
>>> m.connect('gallery', 'images/gallery/:(image_id).jpg')
>>> url_for('gallery_thumb', image_id=1)
'/images/gallery/1_thumbnail.jpg'
>>> url_for('gallery', image_id=1)
'/images/gallery/1_thumbnail.jpg'
And the new option:
>>> m.hardcode_names = True
>>> url_for('gallery_thumb', image_id=1)
'/images/gallery/1_thumbnail.jpg'
>>> url_for('gallery', image_id=1)
'/images/gallery/1.jpg'
Routes trunk can be installed with:
sudo easy_install Routes==dev
Cheers,
Ben
smime.p7s
Description: S/MIME cryptographic signature
