controller
¶
No app built with Seshat does much without controllers. This module provides a base controller class which can be used right away in its current state, or can be inherited from to create more advanced or custom controllers.
Basic use is like so:
from seshat.controller import BaseController
class index(BaseController):
def GET(self):
return "<h1>WAT</h1>"
If you see something along the lines of ‘Content Generating Request Method’ it
will usually mean GET()
, POST()
, or any other HTTP method verb which
might be given to the controller.
-
class
seshat.controller.
BaseController
(request)[source]¶ The parent of all controllers which Seshat will serve.
To use this to make a controller, override or add the request method (in all caps) which will be called for this controller. Eg, with the controller:
from seshat.controller import BaseController class index(BaseController): def GET(self): return "<h1>WAT</h1>"
then all GET method requests to this controller will return with the text <h1>WAT</h1> however all POST, PUT, DELETE calls will return as a blank page, since those methods are not overridden.
Note
Support for Not Supported status codes may be added later, ironically.
-
post_init_hook
()[source]¶ Called at the end of __init__ this allows you to customize the creation process of your controller, without having to override __init__ itself.
This should accept nothing and return nothing.
-
pre_content_hook
()[source]¶ Called before the generating request method is called and should return either None or
Head
orBaseAction
object.If there is a returned value other than None, this will skip calling the content generating request method and simply return directly to dispatch.
A good example of the use for this hook would be for authentication. You could for example, check the id set through the cookie and compare it to a database entry. If the cookie is not currently in use (ie, user not logged in, or similar) then you could do:
return Head("401")
or perhaps:
return actions.Unauthorized()
Return type: Head
orBaseAction
or None
-
post_content_hook
(content)[source]¶ Gets called after the content generating request method has been called. This can be to further modify the content which is returned, or perform some other action after each request.
Parameters: content (str) – the content from the content generating request method that was called. Returns: The original or modified content Return type: str
-