2013-04-14 203 views
1

我想從我的django項目中使用Java調用一些類。 這裏是我的代碼:從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 

任何想法解決它? 我相信進口有問題

回答

1

標準版的Jython與Python 2.5兼容。如documentation on running Django on Jython中所述,Django 1.5僅在Python 2.6以上版本中兼容。您將需要運行Jython的2.7測試版,或Django的舊版本1.4。

+0

謝謝,我會盡快嘗試 – Walucas