質問

IronPythonを使用してASP.NET MVCを試した人はいますか?最近多くのPython開発を行ったので、ASP.NET MVCプロジェクトの可能性があるので、この言語を使い続けるといいでしょう。

特に、LINQなどの.NET機能を使用してPythonの動的な側面を活用することに興味があり、これが可能かどうかを知りたいです。特定の動的プログラミングで実行可能な他のルートは、 dynamic キーワードを使用したC#4.0です。

思考、経験?

役に立ちましたか?

解決

はい、 DLRチームのMVCの例があります

Spark にも興味があるかもしれません。

他のヒント

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-methodsを使用できます

@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")
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top