7

As much as I enjoy building on ASP.NET MVC, it's time to move off Windows.

I'd like to switch to something Python-based with the least amount of pain.

Without discussing the merits of or reasons for switching, which Python web framework is most similar to ASP.NET MVC 3 in terms of architecture?

Architectural Examples

I'm talking about the flow, not the language.

Typical .NET Route

routes.MapRoute( // maps requests at /Product/ to ProductController
    "Products", // Route name
    "Product/{action}/{id}", // URL with parameters
    new { controller = "Product", action = "Index", id = UrlParameter.Optional }
        // Parameter defaults
);

Typical .NET controller

public class ProductController
{
    public ActionResult Index(IndexInputModel inputModel)
    {
        // do something with inputModel ...
        var viewModel = new ProductIndexViewModel()
        {
            Products = productList;
        }
        return View("~/Views/Product/Index.cshtml", viewModel);
    }
    // ...
}

Typical ~/Views/Product/Index.cshtml .NET Razor View

@model ProductIndexViewModel

<h2>Products</h2>
@foreach (var product in Model.Products)
{
    <h3>@product.Title</h3>
    <p>@product.Description</p>
    <span class="price">@product.Price</span>
}
Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
  • why not ruby? most people, like rob conery, etc moved from asp.net to ruby on rails – Shawn Mclean Feb 12 '12 at 22:14
  • @ShawnMclean, what kind of questions are those? Why not ruby (coz Rob Conery does it)? Why not PHP (coz Facebook does it)? Why not Java (coz google does it)? Why not XXX (where you could put anything you like in the place of XXX, coz YYY does it)? I mean Stack Overflow is not some discussion board. It's a programming related Q & A site where people should be asking specific questions. – Darin Dimitrov Feb 12 '12 at 22:57
  • 1
    @DarinDimitrov its a suggestive question. Now calm down, not because the guy is trying to find something outside of windows you have to flip out like that. :( – Shawn Mclean Feb 13 '12 at 04:32

1 Answers1

2

Django has some similarities. But python is not strongly typed as .Net, so I think you are going to see quite a bit of differences, no matter which framework you end up with.

Klaus Byskov Pedersen
  • 117,245
  • 29
  • 183
  • 222
  • Django is the gorilla in the room. I do like the strong-typing aspect of .NET, but let's look past that. Are there any other frameworks to consider? – Petrus Theron Feb 12 '12 at 23:18
  • Actually Python is [strongly typed](http://wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%20language%20and%20also%20a%20strongly%20typed%20language) – P2bM Feb 13 '12 at 20:34
  • .. though typically what us strong-type lovers are looking for is **static** typing. That is, the ability to know at compile-time (and in a good IDE, as we type the code) whether we are making a bonehead mistake in what we attempt to pass as a parameter. Good News: **Python 3 function annotations** can be used by an IDE (e.g. PyCharm), **to declare types**. http://www.python.org/dev/peps/pep-3107/ Finally, the best of both worlds! (Or so I hear .. working in an environment that hasn't yet switched from 2.7) – ToolmakerSteve Dec 16 '13 at 01:12
  • http://stackoverflow.com/questions/6318814/how-can-i-tell-pycharm-what-type-a-parameter-is-expected-to-be talks about PyCharm and declaring types. It turns out that for Python 2, PyCharm can extract type info from traditional (""") python doc comments. – ToolmakerSteve Dec 16 '13 at 01:16