Reputation: 5923
I have a class like this, that generates hyperlinks:
class getLink(obj):
def __init__(self, text, url):
self.text = self.Argument(text)
self.url = self.Argument(url)
def render(self, context):
return "%s %s" % (html.link(self.text(context), self.url(context)))
def link(text, url):
return mark_safe('<a href="%s">%s</a>' % (url, title))
Then to get a Link I do thus:
getLink(text=_('Test'),fn.getUrl())
HTML result:
<a href="/python/tests/">Test</a>
I want to wrap the link inside a <div>
and another inside a <li>
tag. I tried to add the tags directly in getLink()
but doesn't work
getLink("<div>" + text=_('Test'),fn.getUrl() + "</div>")
. I'm newbie in Python so sorry if I'm wrong.
Thanks for you help!
Upvotes: 1
Views: 12734
Reputation: 1
@app.route('/')
def googlelink():
return ('<div><a href="%s">%s</a></div>' % ("https://www.google.com","Google"))
Upvotes: 0
Reputation: 11026
Just wrap the result of your function call in the tags you want?
wrapped_in_div = "<div>" + getLink(text=_('Test'),fn.getUrl()) + "</div>"
wrapped_in_li = "<li>" + getLink(text=_('Test'),fn.getUrl()) + "</li>"
Or you can make use of format
:
wrapped_in_div = "<{0}>{1}</{0}>".format("div", getLink(text=_('Test'),fn.getUrl()))
wrapped_in_li = "<{0}>{1}</{0}>".format("li", getLink(text=_('Test'),fn.getUrl()))
Upvotes: 1
Reputation: 31
I hardly understand where your code is from and if you are able to modify it.
But if you are, why not change the link function and wrap the link directly in there?
Like this :
def link(text, url):
return mark_safe('<div><a href="%s">%s</a></div>' % (url, title))
Maybe you should be more explicit.
Upvotes: 3