morepath.publish
– Web publisher¶
Functionality to turn a morepath.Request
into a
morepath.Response
using Morepath configuration. It looks up a
model instance for the request path and parameters, then looks up a
view for that model object to create the response.
The publish module:
- resolves the request into a model object.
- resolves the model object and the request into a view.
- the view then generates a response.
It all starts at publish()
.
-
morepath.publish.
get_view_name
(stack)¶ Determine view name from leftover stack of path segments
Parameters: stack – a list of path segments left over after consuming the path. Returns: view name string or None
if no view name can be determined.
-
morepath.publish.
publish
(request)¶ Handle request and return response.
It uses
resolve_model()
to use the information inrequest
(path, request method, etc) to resolve to a model object.resolve_response()
then creates a view for the request and the object.Parameters: - request –
morepath.Request
instance. - return –
morepath.Response
instance.
- request –
-
morepath.publish.
resolve_model
(request)¶ Resolve request to a model object.
This takes the path information as a stack of path segments in
morepath.Request.unconsumed
and consumes it step by step usingmorepath.TrajectRegistry.consume()
to find the model object as declared bymorepath.App.path()
directive. It can traverse through mounted applications as indicated by themorepath.App.mount()
directive.Param: morepath.Request
instance.Returns: model object or None
if not found.
-
morepath.publish.
resolve_response
(obj, request)¶ Given model object and request, create response.
This uses
get_view_name()
to set up the view name on the request object.If no view name exist it raises
webob.exc.HTTPNotFound
.It then uses
morepath.App.get_view()
to resolve the view for the model object and the request by doing dynamic dispatch.Parameters: - obj – model object to get response for.
- request –
morepath.Request
instance.
Returns: morepath.Response
instance