【问题标题】:Failing to import external scripts using in IronPython DLR in the browser无法在浏览器中使用 IronPython DLR 导入外部脚本
【发布时间】:2010-10-27 03:09:28
【问题描述】:

我正在尝试使用 IronPython in the browser 并尝试导入外部 python 脚本:

<script src="http://gestalt.ironpython.net/dlr-latest.js" type="text/javascript">
</script>
...
<script type="application/python" src="test.py" defer="true"></script>
<script type="application/python">
import test
test.Hello()
</script>

import 语句似乎运行成功(如果 test.py 不存在,它将失败)。但是,它似乎没有加载文件的内容。 test.py 包含以下代码:

document.testing1.innerHTML = 'Hello from test.py'

def Hello():
   window.Alert('Hello from test.py')

事实上,test.py 中的内容似乎没有任何区别。它不会抱怨语法错误。

在您可以从浏览器中访问的 IronPython 控制台中,会发生同样的问题:

>>> import test
>>> dir(test)
['__builtins__', '__doc__', '__file__', '__name__', '__package__']
>>> test.Hello()
Traceback (most recent call last):
  at <module> in <string>, line 1
  at <module> in <string>, line 0
AttributeError: 'module' object has no attribute 'Hello'

我做错了什么?

更新:它可以与新的 IronPython 2.7 beta 1 VS2010 集成一起使用,该集成启动了“Chiron”测试网络服务器,但在我使用 WebMatrix 时不行。我想知道 WebMatrix 上为 .py 文件配置的 mime 类型是否有问题?

【问题讨论】:

    标签: silverlight ironpython dynamic-language-runtime


    【解决方案1】:

    我终于让它工作了。是 MIME 类型导致了问题。我正在使用 WebMatrix 进行测试。我添加了一个带有以下 xml 的 web.config 文件来解决这个问题:

    <configuration>
        <system.webServer>
            <staticContent>
                <mimeMap fileExtension=".py" mimeType="text/python" />
            </staticContent>
        </system.webServer>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 2015-07-29
      • 2010-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-14
      • 1970-01-01
      • 2018-07-03
      • 1970-01-01
      相关资源
      最近更新 更多