How does one return a specific HTTP status code?

18 views
Skip to first unread message

Vipul Ved Prakash

unread,
Feb 5, 2020, 2:22:08 AM2/5/20
to TurboGears
I'd like to return 401 from a controller.  How does one do this? 

best, 
vipul

Vincenzo Castiglia

unread,
Feb 11, 2020, 5:47:17 PM2/11/20
to TurboGears
see https://turbogears.readthedocs.io/en/latest/reference/classes.html#tg.controllers.util.abort
I suggest you to use detail with gettext:
```
from tg import expose, abort
from tg.i18n import ugettext as _
@expose('templates...blah.blah')
def test(self):
    return abort(401, detail=_('pretty message'))
```
take a look also at your controllers/error.py error controller
Reply all
Reply to author
Forward
0 new messages