ASP.NET MVC 上的 IronPython
-
22-07-2019 - |
题
有人尝试过使用 IronPython 的 ASP.NET MVC 吗?最近进行了大量的 Python 开发,当我进入一个潜在的 ASP.NET MVC 项目时,继续使用该语言会很好。
我对利用 .NET 功能(例如 LINQ)利用 Python 的动态方面特别感兴趣,并且想知道这是否可行。对于某些动态编程可能可行的另一种途径是 C# 4.0 及其 dynamic
关键词。
想法、经历?
解决方案
您可能也有兴趣在星火。
其他提示
在 ASP.NET MVC 中使用 IronPython: http://www.codevoyeur.com/Articles/Tags/ironpython.aspx
此页面包含以下文章:
- 用于 ASP.NET MVC 的简单 IronPython ControllerFactory
- 用于 ASP.NET MVC 的简单 IronPython ActionFilter
- 用于 ASP.NET MVC 的简单 IronPython 路由映射器
- 用于 ASP.NET MVC 的不显眼的 IronPython ViewEngine
我目前正在于此。它已经支持了很多东西: https://github.com/simplic-systems/ironpython -aspnet-MVC
它的更多信息:
导入aspnet
模块
import aspnet
您可以编写自己的控制器
class HomeController(aspnet.Controller):
def index(self):
return self.view("~/Views/Home/Index.cshtml")
可以自动注册所有控制器
aspnet.Routing.register_all()
可以使用不同的HTTP的方法
@aspnet.Filter.httpPost
def postSample(self):
return self.view("~/Views/Home/Index.cshtml")
和还有更多。这里是一个非常短的示例
# ------------------------------------------------
# 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")
不隶属于 StackOverflow