【问题标题】:Importing django modules from java从java导入django模块
【发布时间】:2013-04-14 17:51:28
【问题描述】:

我正在尝试使用 Java 从我的 django 项目中调用一些类。 这是我的代码:

PythonInterpreter interpreter = new PythonInterpreter();

        PySystemState sys = Py.getSystemState(); 


        sys.path.append(new PyString("/Library/Python/2.7/site-packages/"));
        sys.path.append(new PyString("/myApps/categoryApp/review/"));

        interpreter.exec("from products.models import Category");

但是我收到了这个错误:

Exception in thread "main" Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/myApps/categoryApp/review/products/models.py", line 4, in <module>
    from django.core.exceptions import ValidationError
  File "/Library/Python/2.7/site-packages/django/core/exceptions.py", line 4, in <module>
    from functools import reduce
ImportError: cannot import name reduce

任何想法解决它? 我认为导入有问题

【问题讨论】:

    标签: java python django jython


    【解决方案1】:

    Jython 的标准版本与 Python 2.5 兼容。如documentation on running Django on Jython 中所述,Django 1.5 仅兼容 Python 2.6 以上。您将需要运行 Jython 的 2.7 beta 版本,或 Django 的较旧的 1.4 版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-26
      • 2021-12-08
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 2013-01-30
      • 1970-01-01
      • 2010-10-17
      相关资源
      最近更新 更多