pylons url_for doesn't yield proper internal static. SCRIPT_NAME is not inserted into the resolved URL

18 views
Skip to first unread message

Way Chuang Ang

unread,
Jul 12, 2011, 10:33:08 PM7/12/11
to pylons-discuss
Hi fellow pylons masters,

I encounter a problem as described in the subject of the mail. I
integrated pylons applications into apache webserver using mod_wsgi.
The configuration for wsgi is as such:

WSGIScriptAlias /mtrace /var/lib/lgmtrace/lgmtrace.wsgi

However, using h.url_for within the mako template doesn't yield proper
url for static internal route as described in
http://pylonsbook.com/en/1.1/urls-routing-and-dispatch.html#internal-static-routes.
I've checked the environment variable in the BaseController of pylons
and SCRIPT_NAME has been properly set to /mtrace.

So, I decided to look into the code of url_for function within the
routes package. As it turns out, environ attribute was never set for
config variables returned from request_config. As a result, the code
that calls for config.environ.get('SCRIPT_NAME') was never executed.

I wonder if anyone can help me on this matter because I'm stucked on
this problem for quite some time already. Has anyone faces the same
situation? How to fix it so that the URL can be resolved correctly. I
couldn't find any results for my problem on google and stackoverflow,
so I guess it must be some sort of configuration error that leads to
this situation. For your information, I use all the default packages
provided by Fedora 14 for mod_wsgi (3.2.2), apache server (2.2.17),
pylons (1.0), routes (1.12).

Thank you.


Regards,
Ang Way Chuang

David Hoese

unread,
Jul 13, 2011, 9:36:56 PM7/13/11
to pylons-discuss
I had a similar problem earlier this year. What exact version of
Routes do you have? Routes 1.12.2 fixed this issue (newest release is
1.12.3).

From change log at http://routes.groovie.org/changes.html:
Fix bug with routes URLGenerator not properly including SCRIPT_NAME
when generating qualified URL’s.

Update your Routes and it should work. Hope this helps.

-Dave

On Jul 12, 9:33 pm, Way Chuang Ang <wcan...@gmail.com> wrote:
> Hi fellow pylons masters,
>
> I encounter a problem as described in the subject of the mail. I
> integrated pylons applications into apache webserver using mod_wsgi.
> The configuration for wsgi is as such:
>
> WSGIScriptAlias /mtrace /var/lib/lgmtrace/lgmtrace.wsgi
>
> However, using h.url_for within the mako template doesn't yield proper
> url for static internal route as described inhttp://pylonsbook.com/en/1.1/urls-routing-and-dispatch.html#internal-....

David Hoese

unread,
Jul 13, 2011, 9:47:28 PM7/13/11
to pylons-discuss
Another issue...
If you check the change log I linked to in my previous message the
newest message for 1.12.3 talks about another bug with SCRIPT_NAME and
the singleton keyword. That was the solution to another problem I had
a while ago...if I remember right.

-Dave

On Jul 13, 8:36 pm, David Hoese <dho...@gmail.com> wrote:
> I had a similar problem earlier this year.  What exact version of
> Routes do you have? Routes 1.12.2 fixed this issue (newest release is
> 1.12.3).
>
> From change log athttp://routes.groovie.org/changes.html:

Ang Way Chuang

unread,
Jul 14, 2011, 3:25:25 AM7/14/11
to pylons-...@googlegroups.com
Thanks, Dave. I had tried 1.12.3. Still, the problem persists. Sigh, I've wasted too much time on this trivial problem. I've decided to work around by prepending the request['SCRIPT_NAME'] in the mako template manually. It's inelegant, but it works.

Regards,
Ang Way Chuang

On 14/07/11 10:47, David Hoese wrote:
> Another issue...
> If you check the change log I linked to in my previous message the
> newest message for 1.12.3 talks about another bug with SCRIPT_NAME and
> the singleton keyword. That was the solution to another problem I had
> a while ago...if I remember right.
>
> -Dave
>
> On Jul 13, 8:36 pm, David Hoese<dho...@gmail.com> wrote:
>> I had a similar problem earlier this year. What exact version of
>> Routes do you have? Routes 1.12.2 fixed this issue (newest release is
>> 1.12.3).
>>
>> From change log athttp://routes.groovie.org/changes.html:
>> Fix bug with routes URLGenerator not properly including SCRIPT_NAME

>> when generating qualified URL�s.

Wyatt Baldwin

unread,
Jul 14, 2011, 11:56:58 AM7/14/11
to pylons-...@googlegroups.com
I don't know if this will help, but the preferred way to generate URLs is to use `pylons.url()`. It's available automatically in templates, so you can replace `${h.url_for('xyz')}` with `${url('xyz')}`.

Ang Way Chuang

unread,
Jul 18, 2011, 9:35:42 PM7/18/11
to pylons-...@googlegroups.com
Darn right, using ${url('/xyz')} works. Thanks a lot.

On 15/07/11 00:56, Wyatt Baldwin wrote:
> I don't know if this will help, but the preferred way to generate URLs is to use `pylons.url()`. It's available automatically in templates, so you can replace `${h.url_for('xyz')}` with `${url('xyz')}`.
>

> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/pylons-discuss/-/WRC01-s37MUJ.
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.

Reply all
Reply to author
Forward
0 new messages