milla.controllers¶
Stub controller classes
These classes can be used as base classes for controllers. While any callable can technically be a controller, using a class that inherits from one or more of these classes can make things significantly easier.
Created: | Mar 27, 2011 |
---|---|
Author: | dustin |
-
class
milla.controllers.
Controller
[source]¶ The base controller class
This class simply provides empty
__before__
and__after__
methods to facilitate cooperative multiple inheritance.
-
class
milla.controllers.
FaviconController
(icon=None, content_type='image/x-icon')[source]¶ A controller for the “favicon”
This controller is specifically suited to serve a site “favicon” or bookmark icon. By default, it will serve the Milla icon, but you can pass an alternate filename to the constructor.
Parameters: - icon – Path to an icon to serve
- content_type – Internet media type describing the type of image used as the favicon, defaults to ‘image/x-icon’ (Windows ICO format)
-
EXPIRY_DAYS
= 365¶ Number of days in the future to set the cache expiration for the icon
-
class
milla.controllers.
HTTPVerbController
[source]¶ A controller that delegates requests based on the HTTP method
Subclasses of this controller should have an instance method for every HTTP method they support. For example, to support the
GET
andPOST
methods, a class might look like this:class MyController(HTTPVerbController): def GET(self, request): return 'Hello, world!' HEAD = GET def POST(self, request): return 'Thanks!'
This example also allows
HEAD
requests, by processing them asGET
requests. Milla handles this correctly, as it does not send a response body forHEAD
requests, even if the controller callable returns one.