Controllers

Controllers in Bast handle the logic of our app as stated in the MVC paradigm M - Model | V - View | C - Controller. To create controllers in Bast

$ panther create:controller MyController

This creates a MyController.py file in the controller directory. The skeleton for the MyController file is

from bast import Controller


class MyController(Controller):
    pass

You can then create any method and use the methods inherent in the controller class

Controller Methods and Functions

class bast.controller.Controller(application, request, **kwargs)[source]
Controller.write_error(status_code, **kwargs)[source]

Handle Exceptions from the server. Formats the HTML into readable form

Controller.view(template_name, kwargs=None)[source]

Used to render template to view

from bast import Controller

class MyController(Controller):
    def index(self):
        self.view('index.html')
Controller.only(arguments)[source]

returns the key, value pair of the arguments passed as a dict object

from bast import Controller

class MyController(Controller):
    def index(self):
        data = self.only(['username'])

Returns only the argument username and assigns it to the data variable.

Controller.except_(arguments)[source]

returns the arguments passed to the route except that set by user

from bast import Controller

class MyController(Controller):
    def index(self):
        data = self.except_(['arg_name'])

Returns a dictionary of all arguments except for that provided by as arg_name

Controller.json(data)[source]

Encodes the dictionary being passed to JSON and sets the Header to application/json

Controller.get(**kwargs)[source]
Controller.post(**kwargs)[source]
Controller.put(**kwargs)[source]
Controller.delete(**kwargs)[source]
Controller.get_argument(name, default=None, strip=True)[source]

Returns the value of the argument with the given name.

If default is not provided, returns None

If the argument appears in the url more than once, we return the last value.

The returned value is always unicode

Controller.get_arguments(name, strip=True)

Returns a list of the arguments with the given name.

If the argument is not present, returns an empty list.

The returned values are always unicode.

Controller.headers()[source]

Returns all headers associated with the request

Controller.header(param)[source]

Returns the header specified by the key provided