On Thu, May 6, 2010 at 8:52 AM, Jonathan Vanasco <[email protected]> wrote:
> just make a function in helpers:
>
> def my_url( u ):
> u2= url(u)
> if config['site_url_scheme'] == 'https':
> something
> else:
> somthing
>
> and call h.my_url() wherever you need it
>
> you could even redefine url() and then access the original, but stuff
> like that can be a PITA to debug when something goes wrong and you
> forget that you did that ( from experience ;) )
# in myapp/lib/helpers.py
from pylons import url as _url
def url(*args, **kw):
if ...:
kw.setdefault("qualified", True)
return _url(*args, **kw)
# In templates
${h.url(...)}
I had a related problem in that I had to create an absolute URL to put
in an email message, and I was getting HTTP instead of HTTPS because I
have Apache proxying to PasteHTTPServer (which runs HTTP). I had to
add an HTTP header to signal I was running under HTTPS:
# In Apache config
RequestHeader set HTTPS 1
# In the controller action
# We set 'HTTP_HTTPS' via a custom directive in Apach:
# "RequestHeader set HTTPS 1". I wish mod_ssl would set a header
# automatically.
protocol = request.environ.get("HTTP_HTTPS") and "https" or "http"
c.incident_url = url("incident", id=c.incident.orr_id, qualified=True,
protocol=protocol)
I don't quite understand your problem though. If you are only running
HTTP or HTTPS, then relative URLs should be fine. And you're not
making an absolute URL for an email, you're just linking to another
page. So unless you need to jump between HTTP and HTTPS, or you're in
a hybrid proxying situation like I am, why do you need to set the
prococol specially?
--
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.