我试图建立一个在Python和Django上运行的软件。该说明说要使用以下命令来生成SQL数据库:

python manage.py migrate

但是,当我这样做时,会出现以下错误:


  python:Traceback(最近一次调用过去):
  
  在第1行:char:1
  
  + python manage.py迁移
  
  + ~~~~~~~~~~~~~~~~~~~~~~~~
  
  + CategoryInfo:未指定:(Traceback(最近的呼叫为last):: String)
          [],RemoteException
  
  + FullyQualifiedErrorId:NativeCommandError
  
  在第10行输入文件“ manage.py”
      execute_from_command_line(sys.argv)
    文件“ C:\ Python27 \ lib \ site-packages \ django \ core \ management__init __。py”,第353行,位于
  execute_from_command_line
      utility.execute()
  
  文件“ C:\ Python27 \ lib \ site-packages \ django \ core \ management__init __。py”,第302行,在
  执行
      设置。INSTALLED_APPS
  
  getattr中的文件“ C:\ Python27 \ lib \ site-packages \ django \ conf__init __。py”,第55行
      self._setup(名称)
  
  _setup中的文件“ C:\ Python27 \ lib \ site-packages \ django \ conf__init __。py”,第43行
      self._wrapped =设置(settings_module)
  
  init文件“ C:\ Python27 \ lib \ site-packages \ django \ conf__init __。py”,第99行
      mod = importlib.import_module(self.SETTINGS_MODULE)
  
  import_module中的文件“ C:\ Python27 \ lib \ importlib__init __。py”,第37行
      进口(名称)
  
  在第117行中的文件“ F:\ directory \ settings.py”
      TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS +(
  
  TypeError:只能将列表(而不是“ tuple”)连接到列表


这似乎表明问题出在“ 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:只能将列表(而不是“tuple”)连接到列表”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35051508/

10-16 22:47