开发者社区> 问答> 正文

Python Web Framework最像ASP.NET MVC 3

尽管我喜欢在ASP.NET MVC上进行构建,但现在该离开Windows了。

我想切换到基于Python且痛苦最少的工具。

在不讨论切换的优点或原因的情况下,就架构而言,哪个Python Web框架与ASP.NET MVC 3最相似?

建筑实例 我说的是流程,而不是语言。

典型的.NET路由

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
);

典型的.NET控制器

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);
    }
    // ...
}

典型的~/Views/Product/Index.cshtml.NET Razor视图

@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>
}

展开
收起
祖安文状元 2020-02-22 17:44:09 481 0
1 条回答
写回答
取消 提交回答
  • Django有一些相似之处。但是python的类型不是.Net,所以我认为无论最终使用哪种框架,您都将看到很多差异。

    2020-02-22 17:44:23
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Web应用系统性能优化 立即下载
高性能Web架构之缓存体系 立即下载
PWA:移动Web的现在与未来 立即下载