Javascript 在web2py中从python字符串呈现HTML,生成@usename链接python

Javascript 在web2py中从python字符串呈现HTML,生成@usename链接python,javascript,jquery,python,html,web2py,Javascript,Jquery,Python,Html,Web2py,在web2py 我试图在web2py服务器端生成的html文件中呈现锚定链接 <a href="http://app/default/profile/">@username</a> 以及其他各种转换。将其传递给javascript并返回到页面将显示链接。python字符串是否有一些特定的东西不能与html很好地通信 在控制器中,字符串由函数调用生成: #code barrowed from luca de alfaro's ucsc cmps183 class exam

web2py

我试图在web2py服务器端生成的html文件中呈现锚定链接

<a href="http://app/default/profile/">@username</a>
以及其他各种转换。将其传递给javascript并返回到页面将显示链接。python字符串是否有一些特定的东西不能与html很好地通信

在控制器中,字符串由函数调用生成:

#code barrowed from luca de alfaro's ucsc cmps183 class examples
def regex_text(s):
    def makelink(match):
        # The title is the matched praase @username
        title = match.group(0).strip()
        # The page is the striped title 'username' lowercase
        page = match.group(1).lower()
        return '%s' % (A(title, _href=URL('default', 'profile', args=[page])))
    return re.sub(REGEX,makelink, s) 

def linkify(s):
    return regex_text(s)

def represent_links(s, v):
    return linkify(s)
它将@username替换为指向其配置文件和args(0)=username的链接,并通过控制器调用发送到视图

def profile():
    link = linkify(string)
    return dict(link=link)

为了安全起见,web2py模板将自动转义通过
{{=…}
插入的任何文本。要禁用转义,可以将文本换行到:


你能在控制器中发布你的代码吗?谢谢你,很简单,但也很令人沮丧。这对我有用!
def profile():
    link = linkify(string)
    return dict(link=link)
{{=XML(link)}}