class watson.framework.controllers.Action[source]

A controller thats methods can be accessed with an _action suffix.


class MyController(controllers.Action):
    def my_func_action(self):
        return 'something'
class watson.framework.controllers.Base[source]

The base class for all controllers.


string – The last action that was called on the controller.

class watson.framework.controllers.FlashMessagesContainer(session)[source]

Contains all the flash messages associated with a controller.

Flash messages persist across requests until they are displayed to the user.


Initializes the container.

Parameters:session (watson.http.session.StorageMixin) – A session object containing the flash messages data.
add(message, namespace='info', write_to_session=True)[source]

Adds a flash message within the specified namespace.

  • message (string) – The message to add to the container.
  • namespace (string) – The namespace to sit the message in.
add_messages(messages, namespace='info')[source]

Adds a list of messages to the specified namespace.

  • messages (list|tuple) – The messages to add to the container.
  • namespace (string) – The namespace to sit the messages in.

Clears the flash messages from the container and session.

This is called automatically after the flash messages have been iterated over.

class watson.framework.controllers.HttpMixin[source]

A mixin for controllers that can contain http request and response objects.


The request made that has triggered the controller


The response that will be returned by the controller


Clears the redirected variables.


The event that was triggered that caused the execution of the controller.


Retrieves all the flash messages associated with the controller.


# within controller action
self.flash_messages.add('Some message')
return {
    'flash_messages': self.flash_messages

# within view
{% for namespace, message in flash_messages %}
    {{ message }}
{% endfor %}
Returns:A watson.framework.controllers.FlashMessagesContainer object.
forward(controller, method=None, *args, **kwargs)[source]

Fowards a request across to a different controller.


string|object – The controller to execute


string – The method to run, defaults to currently called method

Returns:Response from other controller.
redirect(path, params=None, status_code=302, clear=False)[source]

Redirect to a different route.

Redirecting will bypass the rendering of the view, and the body of the request will be displayed.

Also supports Post Redirect Get (http://en.wikipedia.org/wiki/Post/Redirect/Get) which can allow post variables to accessed from a GET resource after a redirect (to repopulate form fields for example).

  • path (string) – The URL or route name to redirect to
  • params (dict) – The params to send to the route
  • status_code (int) – The status code to use for the redirect
  • clear (bool) – Whether or not the session data should be cleared

A watson.http.messages.Response object.


Returns the post variables from a redirected request.


The HTTP request relating to the controller.


The HTTP response related to the controller.

If no response object has been set, then a new one will be generated.

url(route_name, host=None, scheme=None, **params)[source]

Converts a route into a url.

  • route_name (string) – The name of the route to convert
  • host (string) – The hostname to prepend to the route path
  • scheme (string) – The scheme to prepend to the route path
  • params (dict) – The params to use on the route

The assembled url.

class watson.framework.controllers.Rest[source]

A controller thats methods can be accessed by the request method name.


class MyController(controllers.Rest):
    def GET(self):
        return 'something'