On Mar 16, 2011, at 10:48 AM, Ross Peoples wrote:
> Jonathan has done some awesome work with routing, and I hit my first problem.
> I have a table called auth_user_extended, which I use to store extended
> information not included in the default auth_user table. One of the fields in
> this table is an upload field called picture. The actual file in the uploads
> folder is named:
>
> auth_user_extended.picture.####.png (hash marks indicate unique id)
>
> Whenever I use {{=URL('download', row.picture)}} in a view, the resulting URL
> translates the file name into:
>
> /download/auth-user-extended.picture.####.png (notice the dashes instead of
> the underscores)
>
> I don't know if this is the fault of the router, or the URL() component, but
> it will cause a problem whenever an upload field is used in a table with
> underscores. As a temporary workaround, instead of using:
>
> <img src="{{=URL('default/download', row.auth_user_extended.picture)}}" />
>
> I am using replace(), like so:
>
> <img src="{{=URL('default/download',
> row.auth_user_extended.picture).replace('-', '_')}}" />
By default, the router's map_hyphen flag is True, and it maps underscores in
the app, controller and function names to hyphens in the URL. You *could* set
map_hyphen=False in the router, but that's not the problem here.
In the URL you're generating, 'download' is the function and row.picture (or
whatever) is the first arg. But URL interprets a pair of arguments as
controller and function, which isn't right.
You need URL('default', 'download', args=[row.picture])
The URL function shouldn't be regarded as a slightly smart join; it needs to be
able to identify which component is which (a/c/f/args) in order to do its
expansion correctly.