在Jython上使用Django的manage.py runserver

时间:2021-07-17 18:03:45

Can I run Django's internal server for testing with Jython?

我可以运行Django的内部服务器进行Jython测试吗?

I've installed django-jython, but I get this message when I try to run the server:

我已经安装了django-jython,但是当我尝试运行服务器时收到此消息:

jython manage.py runserver 8000

Traceback (most recent call last): File "manage.py", line 2, in <module>
from django.core.management import execute_manager 
ImportError: No module named django

1 个解决方案

#1


1  

This means that Jython cannot find the 'django' module. Here, the first thing Jython is going to do is try to find the django module:

这意味着Jython无法找到'django'模块。在这里,Jython要做的第一件事是尝试找到django模块:

from django.core.management import execute_manager

It fails, and throws ImportError: No module named django.

它失败了,并抛出ImportError:没有名为django的模块。

You should find out where your django module is, it should be a directory named 'django' that contains an __init__.py file.

你应该找到你的django模块的位置,它应该是一个名为'django'的目录,其中包含一个__init__.py文件。

Set your python path for jython to the parent directory. For example, if you find /Users/cassiomelo/code/jython/Lib/site-packages/django/__init__.py, then you should add /Users/cassiomelo/code/jython/Lib/site-packages to the python path. Click the link to see how to set it depending on your Jython version.

将jython的python路径设置为父目录。例如,如果您找到/Users/cassiomelo/code/jython/Lib/site-packages/django/__init__.py,那么您应该将/ Users / cassiomelo / code / jython / Lib / site-packages添加到python路径。单击链接以查看如何根据您的Jython版本进行设置。

The next time Jython will try to import the 'django' module, it will look in the directory of the python path if there is a directory named 'django' with an __init__.py in it and proceed to importing the core submodule, then management, then execute_manager.

下次Jython尝试导入'django'模块时,如果有一个名为'django'的目录,其中包含__init__.py,则会查看python路径的目录,然后继续导入核心子模块,然后管理,然后是execute_manager。

#1


1  

This means that Jython cannot find the 'django' module. Here, the first thing Jython is going to do is try to find the django module:

这意味着Jython无法找到'django'模块。在这里,Jython要做的第一件事是尝试找到django模块:

from django.core.management import execute_manager

It fails, and throws ImportError: No module named django.

它失败了,并抛出ImportError:没有名为django的模块。

You should find out where your django module is, it should be a directory named 'django' that contains an __init__.py file.

你应该找到你的django模块的位置,它应该是一个名为'django'的目录,其中包含一个__init__.py文件。

Set your python path for jython to the parent directory. For example, if you find /Users/cassiomelo/code/jython/Lib/site-packages/django/__init__.py, then you should add /Users/cassiomelo/code/jython/Lib/site-packages to the python path. Click the link to see how to set it depending on your Jython version.

将jython的python路径设置为父目录。例如,如果您找到/Users/cassiomelo/code/jython/Lib/site-packages/django/__init__.py,那么您应该将/ Users / cassiomelo / code / jython / Lib / site-packages添加到python路径。单击链接以查看如何根据您的Jython版本进行设置。

The next time Jython will try to import the 'django' module, it will look in the directory of the python path if there is a directory named 'django' with an __init__.py in it and proceed to importing the core submodule, then management, then execute_manager.

下次Jython尝试导入'django'模块时,如果有一个名为'django'的目录,其中包含__init__.py,则会查看python路径的目录,然后继续导入核心子模块,然后管理,然后是execute_manager。