I have a custom 404 view defined in my Pyramid app:
@view_config(context=HTTPNotFound, renderer='404.pt')
def not_found(self, request):
return {}
It works fine, except that the HTTP status code sent with the content is 200 OK, which is not OK by any means. I’m having the same problem with 403 Forbidden. How can I get Pyramid to send the correct status code?
The exception view is a separate view that provides a spot for you to do whatever you want. Just like any view that uses a renderer, you can affect the response object via
request.responseto modify its behavior. The renderer then fills in the body.