python - 接收错误: "TypeError: can only concatenate list (not "tuple") to list"

标签 python django

我正在尝试设置一个在 Python 和 Django 上运行的软件。说明说使用以下命令生成 SQL 数据库:

python manage.py 迁移

但是,当我这样做时,我收到以下错误:

python : Traceback (most recent call last):

At line:1 char:1

+ python manage.py migrate

+ ~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : NotSpecified: (Traceback (most recent call last)::String)
[], RemoteException

+ FullyQualifiedErrorId : NativeCommandError

File "manage.py", line 10, in execute_from_command_line(sys.argv) File "C:\Python27\lib\site-packages\django\core\management__init__.py", line 353, in execute_from_command_line utility.execute()

File "C:\Python27\lib\site-packages\django\core\management__init__.py", line 302, in execute settings.INSTALLED_APPS

File "C:\Python27\lib\site-packages\django\conf__init__.py", line 55, in getattr self._setup(name)

File "C:\Python27\lib\site-packages\django\conf__init__.py", line 43, in _setup self._wrapped = Settings(settings_module)

File "C:\Python27\lib\site-packages\django\conf__init__.py", line 99, in init mod = importlib.import_module(self.SETTINGS_MODULE)

File "C:\Python27\lib\importlib__init__.py", line 37, in import_module import(name)

File "F:\directory\settings.py", line 117, in TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (

TypeError: can only concatenate list (not "tuple") to list

这似乎表明问题出在“settings.py”文件的第 116 行,如下所示:

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
from django.conf import global_settings

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'game',
    'admin_views',
)

MIDDLEWARE_CLASSES = (
    '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',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'cagweb.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'game/templates/')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'cagweb.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'
#LANGUAGE_CODE = 'fr'

LOCALE_PATHS = (
        os.path.join(BASE_DIR, 'locale'),
)

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATICFILES_DIRS = (
        os.path.join(BASE_DIR, "static"),
)

STATIC_URL = '/static/'

TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
)

有人可以帮助我了解如何解决这个问题吗?

我不确定它是否相关,但我正在使用 Windows 7、Python 2.7 和 Powershell 来尝试运行该软件。

提前谢谢您!如果我遗漏了任何信息,请告诉我,我会发布它。

最佳答案

() 是一个空元组,而 [] 表示一个空列表。

由于 global_settings.TEMPLATE_CONTEXT_PROCESSORSlist 类型,因此您应该只将其连接到另一个列表:

TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + []

关于python - 接收错误: "TypeError: can only concatenate list (not "tuple") to list",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35051508/

相关文章:

python - 使用 Electrum 控制台验证付款

python - 正确使用 Django Mixins

python - 来自 1.1 的新 django 应用程序导致 500 错误

Django 将字段值注释为查询集

django - 用于访问 Django REST 框架的 secret API key

python - 重新采样 pandas 数据帧时的 NaN 值

python - 如何将参数传递给 Python 中 BaseHTTPRequestHandler 类的 GET 处理程序方法

python - 从列表中删除一个子列表,其中的数字已存在于另一个子列表中

python - 使用 pymysql (Python) 在 MySQL 中导入多个列表

django - 如何向请求添加属性,如 'user' 变量