请帮助我在django上用jython连接数据库,并在我放置jython manage.py运行服务器时帮助我处理服务器服务器不运行
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.7b3Libsite-packagesdjangocoremanagement__init__.py", line 399, in execute_from_command_line
utility.execute()
File "C:jython2.7b3Libsite-packagesdjangocoremanagement__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:jython2.7b3Libsite-packagesdjangocoremanagementbase.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:jython2.7b3Libsite-packagesdjangocoremanagementbase.py", line 280, in execute
translation.activate('en-us')
File "C:jython2.7b3Libsite-packagesdjangoutilstranslation__init__.py", line 130, in activate
return _trans.activate(language)
File "C:jython2.7b3Libsite-packagesdjangoutilstranslationtrans_real.py", line 188, in activate
_active.value = translation(language)
File "C:jython2.7b3Libsite-packagesdjangoutilstranslationtrans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "C:jython2.7b3Libsite-packagesdjangoutilstranslationtrans_real.py", line 159, in _fetch
app = import_module(appname)
File "C:jython2.7b3Libsite-packagesdjangoutilsimportlib.py", line 40, in import_module
__import__(name)
File "C:jython2.7b3Libsite-packagesdjangocontribadmin__init__.py", line 6, in <module>
from django.contrib.admin.sites import AdminSite, site
File "C:jython2.7b3Libsite-packagesdjangocontribadminsites.py", line 4, in <module>
from django.contrib.admin.forms import AdminAuthenticationForm
File "C:jython2.7b3Libsite-packagesdjangocontribadminforms.py", line 6, in <module>
from django.contrib.auth.forms import AuthenticationForm
File "C:jython2.7b3Libsite-packagesdjangocontribauthforms.py", line 17, in <module>
from django.contrib.auth.models import User
File "C:jython2.7b3Libsite-packagesdjangocontribauthmodels.py", line 47, in <module>
@python_2_unicode_compatible
File "C:jython2.7b3Libsite-packagesdjangodbmodelsbase.py", line 96, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:jython2.7b3Libsite-packagesdjangodbmodelsbase.py", line 264, in add_to_class
value.contribute_to_class(cls, name)
File "C:jython2.7b3Libsite-packagesdjangodbmodelsoptions.py", line 124, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:jython2.7b3Libsite-packagesdjangodb__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:jython2.7b3Libsite-packagesdjangodbutils.py", line 198, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:jython2.7b3Libsite-packagesdjangodbutils.py", line 113, in load_backend
return import_module('%s.base' % backend_name)
File "C:jython2.7b3Libsite-packagesdjangodbutils.py", line 113, in load_backend
return import_module('%s.base' % backend_name)
File "C:jython2.7b3Libsite-packagesdjangoutilsimportlib.py", line 40, in import_module
__import__(name)
File "C:jython2.7b3Libsite-packagesdjangodbbackendsmysqlbase.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并将数据库后端设置为'ENGINE': 'doj.db.backends.mysql'
这在Jython 上运行Django的官方文档中有记录
- 使用"pip-Install-pymmysql"安装pymysql
- 将以下内容添加到manage.py文件中:
import pymysql
pymysql.install_as_MySQLdb()
- 在DATABASES设置中,使用:
ENGINE': 'django.db.backends.mysql',