python ASP.NET MVC 上的 IronPython
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/441838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IronPython on ASP.NET MVC
提问by Soviut
Has anyone tried ASP.NET MVC using IronPython? Having done a lot of Python development recently, it would be nice to continue with the language as I go into a potential ASP.NET MVC project.
有没有人尝试过使用 IronPython 的 ASP.NET MVC?最近完成了大量 Python 开发,当我进入一个潜在的 ASP.NET MVC 项目时,继续使用该语言会很好。
I'm especially interested in exploiting the dynamic aspects of Python with .NET features such as LINQ and want to know if this will be possible. The other route that may be viable for certain dynamic programming would be C# 4.0 with its dynamic
keyword.
我对利用 .NET 功能(如 LINQ)利用 Python 的动态方面特别感兴趣,并想知道这是否可行。对于某些动态编程可能可行的另一条路线是带有dynamic
关键字的C# 4.0 。
Thoughts, experiences?
想法,经验?
采纳答案by Craig Stuntz
Yes, there is an MVC example from the DLR team.
是的,DLR 团队有一个 MVC 示例。
You might also be interested in Spark.
您可能还对Spark感兴趣。
回答by Igor Zelmanovich
Using IronPython in ASP.NET MVC: http://www.codevoyeur.com/Articles/Tags/ironpython.aspx
在 ASP.NET MVC 中使用 IronPython:http: //www.codevoyeur.com/Articles/Tags/ironpython.aspx
this page contains following articles:
此页面包含以下文章:
- A Simple IronPython ControllerFactory for ASP.NET MVC
- A Simple IronPython ActionFilter for ASP.NET MVC
- A Simple IronPython Route Mapper for ASP.NET MVC
- An Unobtrusive IronPython ViewEngine for ASP.NET MVC
- 用于 ASP.NET MVC 的简单 IronPython ControllerFactory
- 用于 ASP.NET MVC 的简单 IronPython ActionFilter
- 用于 ASP.NET MVC 的简单 IronPython 路由映射器
- 用于 ASP.NET MVC 的不显眼的 IronPython 视图引擎
回答by BendEg
I'm currently working on this. It already supports a lot of things: https://github.com/simplic-systems/ironpython-aspnet-mvc
我目前正在研究这个。它已经支持很多东西:https: //github.com/simpli-systems/ironpython-aspnet-mvc
more information on this:
更多信息:
Import the aspnet
module
导入aspnet
模块
import aspnet
You can write your own controller
您可以编写自己的控制器
class HomeController(aspnet.Controller):
def index(self):
return self.view("~/Views/Home/Index.cshtml")
You can automatically register all controller
您可以自动注册所有控制器
aspnet.Routing.register_all()
You can use different http-methods
您可以使用不同的 http 方法
@aspnet.Filter.httpPost
def postSample(self):
return self.view("~/Views/Home/Index.cshtml")
And there is much more. Here is a very short example
还有更多。这是一个非常简短的示例
# ------------------------------------------------
# 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")