Friday, 9 August 2013

Globally redirecting in Pyramid...this is printing to the console twice

Globally redirecting in Pyramid...this is printing to the console twice

thanks to Michael Merickel I was able to globally redirect an ip address.
I could have added this as a comment but decided on another question. His
code gives the user an error message. I'd like to also receive an alert
when this happens. I did it by a simple print statement but it
(annoyingly) prints the message twice. I'm only making 1 request on a
simple view (no css files, no js, etc). Is it actually requesting it
twice?
@subscriber('pyramid.events.NewRequest')
def newrequest(event):
request = event.request
if request.remote_addr.startswith('66.'):
print 'hey, we got one...',
raise SomeException('my custom message')
@view_config(context=SomeException, renderer='string')
def exc_view(exc, request):
print 'and another'
return exc.message
Result:
hey, we got one...and another
hey, we got one...and another # why the extra line?

No comments:

Post a Comment