All handlers and middleware receive an instance of the Request class and must return an instance of the Response class.
This document explains the APIs for Response and Request.
A dictionary of the given GET variables.
A dictionary of the given POST variables. If a multiple key-value pairs has the same key name, the dictionary value for the key will be a list of the values.
A dictionary of the given files. As with the POST variables, multiple keys with the same name will result in a list. The values are tuples consisting of the filename and a file-like object.
An instance if RequestCookieHandler which provides the following API.
Return the value of a signed cookie, or None if it doesn’t exist. Raises CookieHashInvalid or CookieHashMissing if the user has altered the cookies in any way.
Return the value of a cookie without validating it’s authenticity. Returns None if the cookie doesn’t exist.
The environment as passed from WSGI.
The base response class. Constructor initializes the attributes with its given values. If default_content_header is true, and Content-Type is not passed in headers, the content type defined in pyroutes.settings.DEFAULT_CONTENT_TYPE will be added to the headers automatically.
The status code can be passed as either a full status code or an integer corresponding to a standard code.
A string or an iterable object that is passed to the browser.
The HTTP status code sent to the client. Can be either a full string representation of the status code, or just the number id.
A list of tuples with key-value pairs of headers and their value.
An instance of ResponseCookieHandler which provides the following API.
Adds a signed cookie to the response. The expires parameter must be an instance of datetime.datetime and set the cookie expiration to its value. Defaults to infinite lifetime.
Same functionality as add_cookie only the cookie will not be signed, and is not tamper proof.
Deletes a cookie from the browser.
A redirect shortcut class for redirection responses. This class can make two types of redirects:
- Absolute path redirects: When you want do redirect to outside your application.
- Root App relative redirect: If you want your redirection relative to the root application path.
- Site relative redirect: If you want your redirection relative to the base of the domain.
- Current URL relative redirect: If you want your redirection relative to the current URL value.
Example of these uses, assuming your app is installed on http://example.com/apps/myapp:
- Redirect('http://pyroutes.com/') for a redirect to pyroutes.com.
- Redirect('/some/path') for a redirect to http://example.com/apps/myapp/some/path. Ignores current URL.
- Redirect('/other/path', absolute_path=True) to redirect to http://example.com/other/path. Ignores current URL.
- Redirect('relative/path') to redirect to a path relative to the current URL of the user’s browser. E.g. if the user is visiting http://example.com/apps/myapp/foo/ this redirect would go to http://example.com/apps/myapp/foo/relative/path
Base class for all exceptions that produce special error pages. If instances of objects that inherited from HttpException are raised, the ErrorHandlerMiddleware will render a page and return it with the correct HTTP code. The base template can be overriden using settings.CUSTOM_BASE_TEMPLATE and additional template data kan be passed to the exception. Raising a HttpException without passing a location as first parameter is allowed, location is then populated from the PATH_INFO variable.
Template for this HttpException can be overridden using settings.TEMPLATE_403
Template for this HttpException can be overridden using settings.TEMPLATE_404
Template for this HttpException can be overridden using settings.TEMPLATE_500