ASP.NET MVC上的IronPython

Sov*_*iut 24 python linq asp.net-mvc ironpython dynamic

有没有人尝试过使用IronPython的ASP.NET MVC?最近做了很多Python开发,在进入潜在的ASP.NET MVC项目时继续使用该语言会很不错.

我特别感兴趣的是利用LINQ等.NET功能来利用Python的动态方面,并想知道这是否可行.对于某些动态编程可能可行的另一条路径是C#4.0及其dynamic关键字.

思想,经历?

Cra*_*ntz 14

是的,DLR团队有一个MVC示例.

您可能也对Spark感兴趣.


Igo*_*ich 8

在ASP.NET MVC中使用IronPython:http://www.codevoyeur.com/Articles/Tags/ironpython.aspx

此页面包含以下文章:

  • ASP.NET MVC的简单IronPython ControllerFactory
  • 一个简单的IronPython ActionFilter for ASP.NET MVC
  • ASP.NET MVC的简单IronPython路由映射器
  • 一个不引人注目的IronPython ViewEngine for ASP.NET MVC


Ben*_*dEg 5

我正在研究这个问题.它已经支持了很多东西:https://github.com/simplic-systems/ironpython-aspnet-mvc

更多相关信息:

导入aspnet模块

import aspnet
Run Code Online (Sandbox Code Playgroud)

你可以编写自己的控制器

class HomeController(aspnet.Controller):

    def index(self):
        return self.view("~/Views/Home/Index.cshtml")
Run Code Online (Sandbox Code Playgroud)

您可以自动注册所有控制器

aspnet.Routing.register_all()
Run Code Online (Sandbox Code Playgroud)

您可以使用不同的http方法

@aspnet.Filter.httpPost
    def postSample(self):
        return self.view("~/Views/Home/Index.cshtml")
Run Code Online (Sandbox Code Playgroud)

还有更多.这是一个非常简短的例子

# ------------------------------------------------
# This is the root of any IronPython based
# AspNet MVC application.
# ------------------------------------------------

import aspnet

# Define "root" class of the MVC-System
class App(aspnet.Application):

    # Start IronPython asp.net mvc application. 
    # Routes and other stuff can be registered here
    def start(self):

        # Register all routes
        aspnet.Routing.register_all()

        # Set layout
        aspnet.Views.set_layout('~/Views/Shared/_Layout.cshtml')

        # Load style bundle
        bundle = aspnet.StyleBundle('~/Content/css')
        bundle.include("~/Content/css/all.css")

        aspnet.Bundles.add(bundle)

class HomeController(aspnet.Controller):

    def index(self):
        return self.view("~/Views/Home/Index.cshtml")

    def page(self):
        # Works also with default paths
        return self.view()

    def paramSample(self, id, id2 = 'default-value for id2'):
        # Works also with default paths
        model = SampleModel()
        model.id = id
        model.id2 = id2
        return self.view("~/Views/Home/ParamSample.cshtml", model)

    @aspnet.Filter.httpPost
    def postSample(self):
        return self.view("~/Views/Home/Index.cshtml")

class SampleModel:
    id = 0
    id2 = ''

class ProductController(aspnet.Controller):

    def index(self):
        return self.view("~/Views/Product/Index.cshtml")
Run Code Online (Sandbox Code Playgroud)