2015-05-14 63 views
0

我想在turbogears中止函數中使用一些HTML消息。Turbogears中止函數自動轉義HTML代碼

雖然名稱不完全匹配(我用的是「tg.abort」功能),這是中止的定義,我發現: abort

目前使用的代碼:

from tg import abort 
message="The following {} occured, this is due to {}, please visit this url : {}".format(error, reason, url) 
abort(status_code=502, detail=message) 

我想要有這樣的事情:

from tg import abort 
message="""The following error occured : {}</br> 
      The most probable reason would be {} </br> 
      <a href="{}">Your solution might be found here</a> 
      """.format(error, reason, url) 
abort(status_code=502, detail=message) 

我認爲內容會自動轉義。

HTML頁面從abort函數生成的,endering是這樣的:

<html> 
 
<head> 
 
    <title>502 Bad Gateway</title> 
 
</head> 
 
<body> 
 
    <h1>502 Bad Gateway</h1> 
 
    Bad gateway.<br /><br /> 
 
The following error occured : hungry&lt;br/&gt; 
 
The most probable reason would be : maybe you should eat &lt;/br&gt; 
 
&lt;a href=&quot;http://dummyurl&quot;&gt;Your solution might be found here&lt;/a&gt; 
 

 

 

 
</body> 
 
</html>

如果你有如何插入HTML代碼沒有逃脫任何想法,我會非常有興趣。 另外我真的很關注abort方法,我知道我可以使用一些專門的頁面來使用模板框架(如網站的其他部分)。

非常感謝。

問候

回答