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:

classMyApp(App):pass

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

@MyApp.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.

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.