Package cherrypy :: Module _cperror :: Class HTTPRedirect
[hide private]
[frames] | no frames]

Class HTTPRedirect

source code

              object --+            
                       |            
exceptions.BaseException --+        
                           |        
        exceptions.Exception --+    
                               |    
               CherryPyException --+
                                   |
                                  HTTPRedirect

Exception raised when the request should be redirected.

This exception will force a HTTP redirect to the URL or URL's you give it. The new URL must be passed as the first argument to the Exception, e.g., HTTPRedirect(newUrl). Multiple URLs are allowed in a list. If a URL is absolute, it will be used as-is. If it is relative, it is assumed to be relative to the current cherrypy.request.path_info.

If one of the provided URL is a unicode object, it will be encoded using the default encoding or the one passed in parameter.

There are multiple types of redirect, from which you can select via the ``status`` argument. If you do not provide a ``status`` arg, it defaults to 303 (or 302 if responding with HTTP/1.0).

Examples:

   raise cherrypy.HTTPRedirect("")
   raise cherrypy.HTTPRedirect("/abs/path", 307)
   raise cherrypy.HTTPRedirect(["path1", "path2?a=1&b=2"], 301)

See :ref:`redirectingpost` for additional caveats.

Instance Methods [hide private]
 
__init__(self, urls, status=None, encoding=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
set_response(self)
Modify cherrypy.response status, headers, and body to represent self.
source code
 
__call__(self)
Use this exception as a request.handler (raise self).
source code

Inherited from exceptions.Exception: __new__

Inherited from exceptions.BaseException: __delattr__, __getattribute__, __getitem__, __getslice__, __reduce__, __repr__, __setattr__, __setstate__, __str__, __unicode__

Inherited from object: __format__, __hash__, __reduce_ex__, __sizeof__, __subclasshook__

Class Variables [hide private]
  status = None
The integer HTTP status code to emit.
  urls = None
The list of URL's to emit.
  encoding = 'utf-8'
The encoding when passed urls are not native strings
Properties [hide private]

Inherited from exceptions.BaseException: args, message

Inherited from object: __class__

Method Details [hide private]

__init__(self, urls, status=None, encoding=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

set_response(self)

source code 

Modify cherrypy.response status, headers, and body to represent self.

CherryPy uses this internally, but you can also use it to create an HTTPRedirect object and set its output without *raising* the exception.