morepath.view – View registry¶
A view is a function that returns something. This can be a
morepath.Response, but it can also be a structure (such a
dict) that should be rendered to a response. If the view is a JSON
view this dumps this structure as JSON. If the view is a HTML view
this structure can be converted to HTML using a template.
View(func, render=None, load=None, permission=None, internal=False, code_info=None)¶
A view as registered with
- func – view function. Given a model instance and a request argument, this function must return either a structure that can be turned into a response or a response.
- render – a function used to render view function return value as a response.
- load – a function used to load the body data into a third argument to the view.
- permission – permission class that the identity must have according to permission rules. If the view doesn’t have the permission access is forbidden.
- internal – bool to indicate whether this view is internal.
If the view is internal you can use it with
morepath.Request.view()but it doesn’t have a URL and will be 404 Not Found.
__call__(app, obj, request)¶
Render a model instance.
If view is internal it cannot be rendered.
If the identity does not have the permission for this object according to the permission rules then
Any functions specified using
morepath.Request.after()are run against the response once it is created, if that response is not an error.
- obj – the model instance
- request – the request
Default render function for view if none was supplied.
This just assumes the content is a string and renders it into a response.
- content – content as returned by view function.
- request – request object
a response instance with the content.