Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #155 (closed defect: fixed)

Opened 14 years ago

Last modified 12 years ago

make tg.url() more useful

Reported by: Jens Owned by: anonymous
Priority: normal Milestone: 0.9
Component: TurboGears Version: 0.8
Severity: minor Keywords: tg.url server.webpath


after playing a bit with tg.url() i am missing a feature to obtain the path to my app. i thought of thomething like tg.url('/'). while trying this i encountered the problem that i used a trailing slash when setting server.webpath .

My suggestion: make tg.url remove occurences of double and triple slashes after generating the url. that would fix all of this.


turbogears_url_slash_fix.patch Download (537 bytes) - added by tg@… 14 years ago.
Patch for turbogears/init.py to norm multiple slashes to single
tg_slash_fix_2.patch.txt Download (591 bytes) - added by Mark Godfrey <mark@…> 14 years ago.
fix for '/' not being handled in the original patch

Change History

comment:1 Changed 14 years ago by anonymous

  • Milestone set to 0.9

changed milestone to 0.9.

Changed 14 years ago by tg@…

Patch for turbogears/init.py to norm multiple slashes to single

comment:2 Changed 14 years ago by Fredrik Steen <tg@…>

The attached patch will change so that turbogears.url() will reduce multiple slashes to a single slash.


//a/b//c/ to /a/b/c/
/a/b/c// to /a/b/c/

Changed 14 years ago by Mark Godfrey <mark@…>

fix for '/' not being handled in the original patch

comment:3 Changed 14 years ago by Mark Godfrey <mark@…>

Unfortunately, the original patch didn't handle paths beginning with '/' correctly for me (might be related to having a server.webpath set), where as the slight modification to the original patch does.

comment:4 Changed 14 years ago by michele

  • Summary changed from make tg.url() more useful to [PATCH] make tg.url() more useful

comment:5 Changed 14 years ago by Jens

  • Keywords server.webpath added

Latest svn version still has major problems using server.webpath to generate valid urls. I hab some cases where a slash was missing to seperate the path. Adding the missing slash to server.webpath or the tg.url parameter often resulted in double slashes. Examples:


comment:6 Changed 14 years ago by Aaron Digulla

Here is another idea: If the url starts with "!", then replace that with the relative or absolute path to the root URL of the app.

This way, you don't have to mess with strange URLs (which might be correct) and chances that a real url will ever start with "!" are low (escaping could then be added if it was ever needed).

What I also would like to see is an optional second parameter to create a relative URL from the first to the second. This would allow to create sites with only relative URLs so one could export those as static HTML or use TG as an editor to modify a site localy and then upload it on the server.

comment:7 Changed 14 years ago by Jens

Using "!" would be very magic. I don't think this is the right way....

comment:8 Changed 14 years ago by Aaron Digulla

Re Jens: I know that "!" is no standard but I've yet to find a more simple and robust way to specify "this path is relative to the app root".

Imagine you want to be able to deploy your app locally (for tests), on a test server (for other deverlopers to share and/or for site admins to give feedback) and finally on the real hardware.

For the local deployment, you often want relative URLs everywhere so you can export the HTML and do link checking or create docs to pass along with the product, etc.

For the test server, you want to be able to set the "root" to some internal path, possibly nested within another app server (for example, to have the test app running inside the prod version below a certain URL).

Also, you sometimes need to be able to say "for xyz, see [url]" where URL is the actual URL of the prod system (example: A download dir which will exist only once, no matter how often you deploy your app). Here, you will want to be able to specify an absolute URL which starts like your prod server but which should stay the same on all servers.

comment:9 Changed 13 years ago by kevin

  • Summary changed from [PATCH] make tg.url() more useful to make tg.url() more useful

Work on this, and the CherryPy? upgrade invalidate this ticket to some extent. I think we need to do a test to see whether the problem reported here (double slashes) still exists.

If you want an absolute URL that does not involve the application path, just make the URL manually. We can likely add options to turbogears.url if other things are necessary, but I don't want to head down the "magic string" road.

comment:10 Changed 13 years ago by Aaron Digulla

If "!" bothers you, how about changing tg.url() to accept a list? Then, you could define a couple of symbols to achive the desired result and users could add their own:

url = tg.url(URL.APP_BASE, 'path/to/something', 'method', anchor=None, query={

'search', 'Google website'


would become:  http://www.turbogears.org/path/to/something/method?search=Google+website

The semantics should be like os.path.join() but with additional stuff for URLs (like parameters and anchors)

The ultimate solution would be a tg.url() method which allows to specify a method to call (TG should then use the meta-information to determine the actual URL) and to pass the parameters of the method as if you would be calling the method directly. The semantics would be: Call this when the user clicks the link.

comment:11 Changed 13 years ago by kevin

  • Status changed from new to closed
  • Resolution set to fixed

I'm closing this ticket. I don't think tg.url generates double slashes at this point, and I'd rather not mix potential new features with this ticket.

Note: See TracTickets for help on using tickets.