request.resource_url or request.resource_path

17 views
Skip to first unread message

Petr Blahoš

unread,
May 29, 2024, 2:32:53 AMMay 29
to pylons-...@googlegroups.com
Hi,
I have been using pyramid for many years and I have always been
using
  • request.resource_url
  • request.static_url
  • or similar ending with _url.
Yesterday when trying to make IIS work as a reverse proxy I noticed
that the links in my pages contain scheme://hostname:port part of the
URL too. So I am thinking: Should I always use the resource_path / static_path
functions to make the URLs?

What are your thoughts?
Thanks, 
Petr

Mike Orr

unread,
May 29, 2024, 11:04:08 AMMay 29
to pylons-...@googlegroups.com
I prefer the '*_path' methods to get relative URLs that automatically
adjust to more environments, and to minimize the chance of mismatches
behind reverse proxies. Except in redirects where I've read the target
is supposed to be an absolute URL. Some other Pyramid developers
prefer the '*_url' methods.
> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/CA%2ByMeXVZ%3DxN6yYCC-oRU3W%3D7J52xzAuQfVwJSyyKep4gpg%3Do5Q%40mail.gmail.com.



--
Mike Orr <slugg...@gmail.com>

Michael Merickel

unread,
May 29, 2024, 11:13:08 AMMay 29
to pylons-...@googlegroups.com
It really doesn’t make a difference imo. If you are using path to get around a proxy misconfig in your WSGI env then stop and go fix the misconfig because as Mike said, certain things like a Location header in a redirect are required to be absolute and will be incorrectly computed if your env’s http scheme, host, and script_name aren’t right.

- Michael

> On May 29, 2024, at 09:04, Mike Orr <slugg...@gmail.com> wrote:
>
> I prefer the '*_path' methods to get relative URLs that automatically
> To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/CAH9f%3Duqh7TCu2e5Upy2hSt7gh8BxxMdv8b6gRqwVeYoZEnF11Q%40mail.gmail.com.

Mike Orr

unread,
May 29, 2024, 1:46:48 PMMay 29
to pylons-...@googlegroups.com
The '*_path' methods also make the generated HTML easier to read,
because they're shorter and focus on the changing part.
--
Mike Orr <slugg...@gmail.com>

Jonathan Vanasco

unread,
May 29, 2024, 7:45:57 PMMay 29
to pylons-discuss
I use `_path` and keep all urls relative in most of my code.

When I need an absolute url, such as for a canonical tag, I pull the prefix off a global variable.

I will also use a `<base >` tag to set the base url for relative urls.

I find this easier for the following situations, so just do it for all situations:
* multi tenant applications
* shifting domains and ports (dev/staging/etc) where I don't want to worry about configuring multiple files with the domain/port

if _url works for you, awesome.

I probably only use the _path commands 1% of the time that involves generating urls though. most of that stuff in my apps is handled by business logic.


Reply all
Reply to author
Forward
0 new messages