views:

21

answers:

1

How can I response a 403 status code?

I was following some example which had this: raise webapp.Error(403). So I thought that this would give me a 403 but it just gives me a regular 500 server error instead.

This is complete example:

def administrator(method):
    ''' credit: 
        http://github.com/btbytes/teh/blob/master/utils.py 

        decorator to restrict access to admin areas
    '''
    @functools.wraps(method)
    def wrapper(self, *args, **kwargs):
        user = users.get_current_user()
        if not user:
            if self.request.method == "GET":
                self.redirect(users.create_login_url(self.request.uri))
                return
        if not users.is_current_user_admin():
            raise webapp.Error(403)
        else:
            return method(self, *args, **kwargs)
    return wrapper

This is where I got it: http://bitbucket.org/abernier/yab/src/tip/handlers/admin.py

+2  A: 

Use self.error(403).

http://code.google.com/appengine/docs/python/tools/webapp/redirects.html

Amber