在Django Admin登录屏幕上获取错误

时间:2016-09-18 15:22:10

标签: python django django-admin

我是使用Django进行Web开发的新手,我正在关注Django教程(PollsApp)进行学习。当我尝试启动Django Admin面板时,我得到一个异常'不能将序列乘以'tuple'类型的非int。

有人可以建议我缺少什么吗?

以下是追溯:

***Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/login/?next=/admin/
Django Version: 1.10.1
Python Version: 3.4.3
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'polls.apps.PollsConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "E:\Python34\lib\site-packages\django\core\handlers\exception.py" in inner
  39.             response = get_response(request)
File "E:\Python34\lib\site-packages\django\core\handlers\base.py" in _legacy_get_response
  249.             response = self._get_response(request)
File "E:\Python34\lib\site-packages\django\core\handlers\base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)
File "E:\Python34\lib\site-packages\django\core\handlers\base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "E:\Python34\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)
File "E:\Python34\lib\site-packages\django\contrib\admin\sites.py" in login
  377.         return login(request, **defaults)
File "E:\Python34\lib\site-packages\django\contrib\auth\views.py" in inner
  47.         return func(*args, **kwargs)
File "E:\Python34\lib\site-packages\django\views\decorators\debug.py" in sensitive_post_parameters_wrapper
  76.             return view(request, *args, **kwargs)
File "E:\Python34\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  149.                     response = view_func(request, *args, **kwargs)
File "E:\Python34\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)
File "E:\Python34\lib\site-packages\django\contrib\auth\views.py" in login
  82.             auth_login(request, form.get_user())
File "E:\Python34\lib\site-packages\django\contrib\auth\__init__.py" in login
  109.         request.session.cycle_key()
File "E:\Python34\lib\site-packages\django\contrib\sessions\backends\base.py" in cycle_key
  311.         self.create()
File "E:\Python34\lib\site-packages\django\contrib\sessions\backends\db.py" in create
  54.                 self.save(must_create=True)
File "E:\Python34\lib\site-packages\django\contrib\sessions\backends\db.py" in save
  87.                 obj.save(force_insert=must_create, force_update=not must_create, using=using)
File "E:\Python34\lib\site-packages\django\db\models\base.py" in save
  796.                        force_update=force_update, update_fields=update_fields)
File "E:\Python34\lib\site-packages\django\db\models\base.py" in save_base
  824.             updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "E:\Python34\lib\site-packages\django\db\models\base.py" in _save_table
  908.             result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "E:\Python34\lib\site-packages\django\db\models\base.py" in _do_insert
  947.                                using=using, raw=raw)
File "E:\Python34\lib\site-packages\django\db\models\manager.py" in manager_method
  85.                 return getattr(self.get_queryset(), name)(*args, **kwargs)
File "E:\Python34\lib\site-packages\django\db\models\query.py" in _insert
  1045.         return query.get_compiler(using=using).execute_sql(return_id)
File "E:\Python34\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql
  1053.             for sql, params in self.as_sql():
File "E:\Python34\lib\site-packages\django\db\models\sql\compiler.py" in as_sql
  1038.             result.append(self.connection.ops.bulk_insert_sql(fields, placeholder_rows))
File "E:\Python34\lib\site-packages\mysql\connector\django\operations.py" in bulk_insert_sql
  223.         return "VALUES " + ", ".join([items_sql] * num_values)
Exception Type: TypeError at /admin/login/
Exception Value: can't multiply sequence by non-int of type 'tuple'***

修改的 这是我在settings.py中的数据库:

DATABASES = {
    'default': {
        'ENGINE': 'mysql.connector.django', 
        'NAME': 'polls',
        'USER': '.....',
        'PASSWORD': '.....',
        'HOST': 'localhost',   # Or an IP Address that your DB is hosted on
        'PORT': '4928',
    }
}

1 个答案:

答案 0 :(得分:1)

您使用的是什么版本的Django?我遇到了同样的问题......看起来像Django / MySQL方面的问题。

您需要在

中更新bulk_insert_sql
  

{python package directory} /mysql/connector/django/operations.py。

它应该是这样的:

    def bulk_insert_sql(self, fields, placeholder_rows):
    """
        Format the SQL for bulk insert
    """
        placeholder_rows_sql = (", ".join(row) for row in placeholder_rows)
        values_sql = ", ".join("(%s)" % sql for sql in placeholder_rows_sql)
        return "VALUES " + values_sql

See here