On 05/06/10 19:45, Mike Orr wrote: > 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(...)} >
Writing a helper function was my first thought as well, especially wrapping args and kwargs as Mike suggested. I wasn't sure, though, because I wanted to stay as close to the "vanilla" calls as possible. > 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? > That's the thing, I need to force HTTPS for some links only. I don't want to force entire site into HTTPS as that would be a waste of resources, and can be done at the webserver level. So only links that require SSL should be formatted with https, as well as redirects in relevant controllers, in case plain HTTP was used. Thanks both, my problem is solved for now. ;) Vlad -- 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.
