On Mon, Jun 20, 2011 at 1:32 AM, Thomi <[email protected]> wrote:
> Hi,
>
> I have a pylons web-app that generates links to controller actions
> using routes.url_for, and links to static files (CSS, javascript,
> images etc) using the functions defined in webhelpers.html.tags. This
> works fine while my web-app is hosted at the root of the server (i.e.,
> the web-app is run from '/'). However, if I move the web-app to some
> other location, like '/foobar/', the url_for links work perfectly, but
> the functions under webhelpers.html.tags still generate links pointing
> to '/path/to/resource' rather than '/foobar/path/to/resource'.
>
> My understanding is that WSGI defines an environment variable called
> SCRIPT_NAME that contains the path leading up to the application (so /
> foobar in this example). My guess is that url_for is paying attention
> to this environment variable and changing it's generated URLs
> accordingly.
>
> Is there a way to get the webhelpers module to do the same?
No, WebHelpers is a generic package; it doesn't know how its caller
handlers URLs or requests. You embed the URL call as an argument.
tags.form(action=url("whatever"))
tags.stylesheet_link(url("/stylesheets/default.css"))
``url_for`` is deprecated. Are you maintaining an old Pylons 0.9.7
application? ``pylons.url`` (or ``url`` in templates) was introduced
in Pylons 0.9.7, and url_for was retired in Pylons 1.
The only part or WebHelpers that generates URLs internally is
webhelpers.paginate. It has backward compatibility code to work with
either Pylons 1 or 0.9.7, url_for or pylons.url. (The url_for code
depends on a magic undocumented singleton shared between Routes,
Pylons, and WebHelpers; that's why it was deprecated.)
The script name is available in Pylons as ``request.environ["SCRIPT_NAME"]``.
--
Mike Orr <[email protected]>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en.