请帮助我将数据库与django上的jython连接,并在我将jython manage.py run server放在服务器上时帮助我运行服务器

DATABASES = {
    'default': {
        #'ENGINE': 'doj.backends.zxjdbc.sqlite3',
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'tanagraweb',
        'USER': 'root',
        'PASSWORD': 'root',
        'HOST': '127.0.0.1',
        'PORT': '3306',
    }
}

Django扔这个:
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\jython2.7b3\Lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "C:\jython2.7b3\Lib\site-packages\django\core\management\__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\jython2.7b3\Lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\jython2.7b3\Lib\site-packages\django\core\management\base.py", line 280, in execute
    translation.activate('en-us')
  File "C:\jython2.7b3\Lib\site-packages\django\utils\translation\__init__.py", line 130, in activate
    return _trans.activate(language)
  File "C:\jython2.7b3\Lib\site-packages\django\utils\translation\trans_real.py", line 188, in activate
    _active.value = translation(language)
  File "C:\jython2.7b3\Lib\site-packages\django\utils\translation\trans_real.py", line 177, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "C:\jython2.7b3\Lib\site-packages\django\utils\translation\trans_real.py", line 159, in _fetch
    app = import_module(appname)
  File "C:\jython2.7b3\Lib\site-packages\django\utils\importlib.py", line 40, in import_module
    __import__(name)
  File "C:\jython2.7b3\Lib\site-packages\django\contrib\admin\__init__.py", line 6, in <module>
    from django.contrib.admin.sites import AdminSite, site
  File "C:\jython2.7b3\Lib\site-packages\django\contrib\admin\sites.py", line 4, in <module>
    from django.contrib.admin.forms import AdminAuthenticationForm
  File "C:\jython2.7b3\Lib\site-packages\django\contrib\admin\forms.py", line 6, in <module>
    from django.contrib.auth.forms import AuthenticationForm
  File "C:\jython2.7b3\Lib\site-packages\django\contrib\auth\forms.py", line 17, in <module>
    from django.contrib.auth.models import User
  File "C:\jython2.7b3\Lib\site-packages\django\contrib\auth\models.py", line 47, in <module>
    @python_2_unicode_compatible
  File "C:\jython2.7b3\Lib\site-packages\django\db\models\base.py", line 96, in __new__
    new_class.add_to_class('_meta', Options(meta, **kwargs))
  File "C:\jython2.7b3\Lib\site-packages\django\db\models\base.py", line 264, in add_to_class
    value.contribute_to_class(cls, name)
  File "C:\jython2.7b3\Lib\site-packages\django\db\models\options.py", line 124, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "C:\jython2.7b3\Lib\site-packages\django\db\__init__.py", line 34, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "C:\jython2.7b3\Lib\site-packages\django\db\utils.py", line 198, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "C:\jython2.7b3\Lib\site-packages\django\db\utils.py", line 113, in load_backend
    return import_module('%s.base' % backend_name)
  File "C:\jython2.7b3\Lib\site-packages\django\db\utils.py", line 113, in load_backend
    return import_module('%s.base' % backend_name)
  File "C:\jython2.7b3\Lib\site-packages\django\utils\importlib.py", line 40, in import_module
    __import__(name)
  File "C:\jython2.7b3\Lib\site-packages\django\db\backends\mysql\base.py", line 17, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

我研究发现这是mysql的连接器,但我不知道为什么这不起作用
如果有人在Jython Django有个项目我会非常感激这太难了

最佳答案

尽管MySQLdb是python/django社区中使用最广泛的mysql库,但是您不能使用它,因为jython不能使用c扩展。
要在django中使用jython,需要安装django-jython并将db backend设置为'ENGINE': 'doj.db.backends.mysql'
这在官方文件Running Django on Jython

关于database - jython上的Django数据库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25517615/

10-15 15:21