Reputation: 65951
When using IS_URL
validator web2py prepends http to the stored value. Now when forming a link in my view I'd like to remove the http and trailing slash.
<div>{{=A('<what goes here?>', _href=business.website)}}</div>
That is, given a url such as:
http://www.example.com/
I want the anchor text to be
www.example.com
(or example.com
)
I understand I can do this via standard python using urlparse.urlsplit
, however wondering if web2py provides this functionality?
If using pure python is the best way to do this, where should the code to strip the url be? View? Controller?
Upvotes: 0
Views: 359
Reputation: 25536
I understand I can do this via standard python using urlparse.urlsplit, however wondering if web2py provides this functionality?
No, web2py does not provide that functionality, so just use standard Python.
If using pure python is the best way to do this, where should the code to strip the url be? View? Controller?
Your choice. If you do it in the view, you can avoid having to pass an additional variable from the controller.
Note, you can do IS_URL(prepend_scheme=None)
if you want to prevent the validator from prepending the "http" (you can also set prepend_scheme
to an alternative, such as "https").
Upvotes: 2