0

I would like to use some HTML messages in the turbogears abort function.

Although the name does not match exactly (I use the 'tg.abort' function), this is the abort definition I found : abort

The code used currently :

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)

I would like to have something like this :

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)

I think the content is automatically escaped.

The Html page generated from the abort function, endering something like this :

<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>

If you have any idea of how to insert html code without escaping, I would be very interested. Also I really am focused on the abort method here, I am aware that I could use some dedicated page that would use a templating framework (like the rest of the website).

Thank you very much.

Regards

Azurtree
  • 369
  • 4
  • 11

1 Answers1

0

The error message is actually exposed by the controllers/error.py code in your application. So if you want to expose the message from abort details you should fetch it and return it in the ErrorController.

This is now done by default on newly quickstarted projects ( see https://github.com/TurboGears/tg2devtools/blob/master/devtools/templates/turbogears/%2Bpackage%2B/controllers/error.py_tmpl#L27 ) but it was not done on old versions.

amol
  • 1,771
  • 1
  • 11
  • 15