mvc
Model-View-Controller framework for Smisk. Provides URL routing, template rendering, leaf filters, and a rich Application base class.
Configuration parameters
smisk.mvc.template_dirPath to the template directory, relative to the application directory.
smisk.mvc.forksNumber of worker processes to fork. Defaults to 0.
Leaf filters
Leaf filters are callables that post-process controller return values before serialization. Register them via Application.leaf_filters.
Functions
smisk.mvc.environment()Returns a dict describing the current runtime environment (version, paths, etc.).
smisk.mvc.main(application_class=None, *args, **kwargs)Convenience entry point. Instantiates application_class, configures it from command-line arguments, and calls
run().smisk.mvc.run(application_class, *args, **kwargs)Alias for
main().smisk.mvc.setup()Set up the MVC subsystem without starting the server. Useful for testing.
Classes
- class
smisk.mvc.Application(smisk.core.Application) -
The MVC application. Handles routing, dispatch, template rendering, and serialization.
templatesTemplate engine instance.
routesRouting table.
serializerDefault serializer for responses.
leaf_filtersList of callables applied to controller return values before serialization.
unicode_errorsError handling mode for unicode encoding. Defaults to
'replace'.autoclear_model_sessionIf True, the SQLAlchemy session is cleared after each request.
run()Start the FastCGI event loop.
service()Called for each request. Performs routing and dispatches to the appropriate controller leaf.
setup()Initialise MVC subsystems. Called automatically before the first request.
error(typ, val, tb)Handle an error. Delegates to
smisk.core.Application.error()unless overridden.call_action(leaf, *args, **kwargs)Call a controller leaf and apply leaf filters.
encode_response(value)Serialize a controller return value.
parse_request()Parse the incoming request and populate
request.get/request.post.response_serializer()Determine the best serializer for the current request based on content negotiation.
send_response(value)Serialize and send value as the response body.
- class
smisk.mvc.Request(smisk.core.Request) -
Extended request with MVC-specific attributes.
serializerThe serializer selected for this request (may be
None).cn_urlThe canonical URL of the matched route.
- class
smisk.mvc.Response(smisk.core.Response) -
Extended response with serialization helpers.
formatExplicit response format override (e.g.
"json"). Bypasses content negotiation.serializerThe serializer to use for this response. If
None, strict TCN applies.fallback_serializerSerializer used when content negotiation fails.
charsetCharacter set for the response. Determined automatically from mimetypes.guess_type when possible.
send_file(path)Send a file to the client. Inherited from
smisk.core.Response.