[web2py] r=request problem.

10 views
Skip to first unread message

annet

unread,
Apr 26, 2010, 10:21:16 AM4/26/10
to web2py-users
In an html e-mail view I have the following links:

{{=A('View it in your browser',
_href=URL(r=request,c='clublocatormail',f='browser_version',args=[item.bedrijfcontactpersoon.bedrijf_id,item.contactpersoon.id]),
_target="_blank")}}

<img src="{{=URL(r=request,c='static',f='crm/media/header.jpg')}}"
alt="Header" width="600" height="192" />


When I send the mail from within: https://admin.fitwise.nl/admin/default/design/mock_crm
the links in the e-mail read like:

<a target="_blank" href="http://mock_crm/clublocatormail/
browser_version/1/3">View it in your browser</a>

<img src="http://mock_crm/static/crm/media/header.jpg">

Whereas they should read:

<a target="_blank" href="http://www.fitwise.nl/mock_crm/
clublocatormail/browser_version/1/3">View it in your browser</a>

<img src="http://www.fitwise.nl/mock_crm/static/crm/media/
header.jpg">


How do I solve this problem?


Kind regards,

Annet.


--
Subscription settings: http://groups.google.com/group/web2py/subscribe?hl=en

mdipierro

unread,
Apr 26, 2010, 10:27:08 AM4/26/10
to web2py-users
<img src="http://www.fitwise.nl/
mock_crm{{=URL(r=request,c='static',f='crm/media/header.jpg')}}"
alt="Header" width="600" height="192" />

You know the hostname, the email program does not.

annet

unread,
Apr 26, 2010, 11:46:36 AM4/26/10
to web2py-users
Massimo,

Isn't the view being rendered by web2py before it's send to the mail
server?

Regards,

Annet

mdipierro

unread,
Apr 26, 2010, 11:56:09 AM4/26/10
to web2py-users
Yes. and the way it is rendered is correct for a web page because the
browser knows the hostname already (since you typed it in to request
the page). The recipient of the email does not.

annet

unread,
Apr 26, 2010, 12:41:03 PM4/26/10
to web2py-users
Now I understand the problem. When I rewrite the _href:

{{=A('View it in your browser', _href="http://127.0.0.1:8000" +
URL(r=request,c='clublocatormail',f='browser_version',args=[item.bedrijfcontactpersoon.bedrijf_id,item.contactpersoon.id]),
_target="_blank")}}

... the problem is solved. I guess I'd best add a variable containing
the "http://127.0.0.1:8000" value e.g. mydomain, and then:

{{=A('View it in your browser', _href=mydomain +
URL(r=request,c='clublocatormail',f='browser_version',args=[item.bedrijfcontactpersoon.bedrijf_id,item.contactpersoon.id]),
_target="_blank")}}


Does anyone know a better solution?

Jonathan Lundell

unread,
Apr 26, 2010, 2:57:35 PM4/26/10
to web...@googlegroups.com
On Apr 26, 2010, at 9:41 AM, annet wrote:

> Now I understand the problem. When I rewrite the _href:
>
> {{=A('View it in your browser', _href="http://127.0.0.1:8000" +
> URL(r=request,c='clublocatormail',f='browser_version',args=[item.bedrijfcontactpersoon.bedrijf_id,item.contactpersoon.id]),
> _target="_blank")}}
>
> ... the problem is solved. I guess I'd best add a variable containing
> the "http://127.0.0.1:8000" value e.g. mydomain, and then:
>
> {{=A('View it in your browser', _href=mydomain +
> URL(r=request,c='clublocatormail',f='browser_version',args=[item.bedrijfcontactpersoon.bedrijf_id,item.contactpersoon.id]),
> _target="_blank")}}
>
>
> Does anyone know a better solution?

Massimo will warn you, correctly, that this isn't a universal solution, but if your server configuration permits it, you might be able to extract your host name from request.env. Have a look at request.env.http_host or request.env.server_name, or at similar variables in request.wsgi.environ.

These won't always be correct (if you're behind a proxy such as Apache mod_proxy, for example), but if they *are* correct, it's probably better than hard-coding your hostname into your application.
Reply all
Reply to author
Forward
0 new messages