Although I’m usually a .NET stacker, I’ve recently been experimenting with Django, a Python-based web framework, because at work we’ve been trying out Sayit, a transcript-rendering tool from mySociety which comes in a Django app. From my limited viewpoint I’m pretty impressed with Django as a tool for building websites quickly. I did the tutorial and I particularly liked the fact that it auto-generated back-end admin pages for you, and (even better) that these could be customised easily using proper code. I have even less knowledge of Microsoft Lightswitch, but it feels as though they’re trying to do the same thing except that Django is more cody and more powerful – unlike Lightswitch, you can’t get anywhere with Django without coding, but you could actually use it to build a public website rather than it being limited to internal-facing business applications.
Anyway, despite the fact that the Django documentation says that it’s not really an MVC framework, I was struck by the similarity of the architecture with ASP.NET MVC, and also the difference in the terminology between the two frameworks. So I’ve written a little dictionary to translate between the two. I particularly like the fact that an ASP.NET MVC Action is analogous to a Django View.
|Model||Model||A class which encapsulates part of the business logic of the application and usually contains data fields which get persisted in a database.|
|View||Template||HTML template which is filled in by the ASP.NET MVC ViewModel / Django Context before being served to the client.|
|Controller||App (arguably)||A collection of handlers usually relating to one Model in ASP.NET MVC, and a closely related set of Models in Django. Only a loose analogy.|
|Action||View||A handler for an HTTP request, taking in data from the user, getting it processed, generating an appropriate ViewModel/Context for the response, allocating a View/Template and passing it back to the user.|
|Routes||Urls||The logic which maps browser URLs to ASP.NET MVC Actions / Django Views.|
|ViewModel||Context||The data that is shown on an ASP.NET MVC View/ Django Template. In some MVC applications the ViewModel is the same as the Model, but often the display logic is a bit different from the business logic, so it’s useful to distinguish between the two.|
|Partial View||Sub template||An HTML fragment which does not form a standalone page in itself but can be used as part of other pages.|
|Area||App (arguably)||In ASP.NET MVC, an Area is related set of Controllers and associated Views and Routes that is partitioned off from the rest of the app. In Django, an App is an independent set of Models, Templates and Views which can be plugged into a website. Only a loose analogy.|