I've been trying to understand how morepath works with the quickstart guide in the documentation.I have a couple of questions regarding the design, and my understanding of what's happening.
So, a model is a resources, pretty much a representation of an object stored in a databse. Atleast, this is how I understand it, if this is so, why can't we have a path assigned to it, inside the classbody itself. So, right now:
# We declare the object
class User(object):
def __init__(self, username, fullname, email):
self.username = username
self.fullname = fullname
self.email = email
# We then assing a path that is handled here
@App.path(model=User, path='/user/{username}')
def get_user(username):
return users.get(username)The question that arises here is this, if all we are doing is using the App.path decorator as a means of registering a
path, and then assigning a filter, in this case get_user, why not just let a view function handle all the url
understanding, and then the eventual rendering? Also, since you're naming a function here, with the App.path decorator, can
you assign multiple masks or filters before the view is finally rendered?
I think what you're asking is basically: why is Morepath not like Flask or almost any other routing framework.
Why not simply have a view function associated with a path instead like these others do?
Routing directly to a view definitely has a benefit of simplicity, but you lose a bunch of nice features.
Morepath gets several benefits of separating these concerns; I tried to document them in the superpowers document and various other places, but I'll try to summarize here:
I'm not entirely sure what you mean by your masks or filters question. What do you mean by masks in particular if this is different from filters? I think it might have something to do with collections and doing a query on them. What you'd typically do is come up with a Collection class in your application that takes whatever things you want to filter with and implements a method called "query" (or whatever) that when executed does the actual query. Then you expose this Collection to a URL, along these lines: