Here we’ve used document_json ourselves. But what now if the
container does not only contain Document instances? What if one of
them is a SpecialDocument? Our document_container_json
function breaks. How to fix it? Easy, we can use
morepath.Request.view():

Ugh! We can’t just change the application as it needs to continue to
work in its original form. Besides, it’s being maintained by someone
else. What do we do now? Monkey-patch? Not at all: Morepath got you
covered. You simply create a new application subclass that extends the
original:

classmy_app(app):pass

We now have an application that does exactly what app does. Now
to override that one view to do what we want:

@my_app.view(model=Document)defwhatwewant(self,request):return"The right thing!"

And we’re done!

It’s not just the view directive that works this way: all Morepath
directives work this way. Using the morepath.App.function()
decorator you could even override the core functionality of Morepath
itself!

Morepath also lets you mount one application within another, allowing
composition-based reuse. See App Reuse for more
information. Using these techniques you can build large applications,
see Building Large Applications.