TypeError:预期的str,字节或OS.Pathike对象,而不是元组,在最小的Django应用程序中



我正在使用django构建应用程序。每当我尝试在'DIRS'设置的CC_2列表中使用os.path.join()时,我都会获得TypeError: expected str, bytes or os.PathLike object, not tuple

BASE_DIR = os.path.dirname(os.path.abspath(__file__)),
# Settings
settings.configure(
    INSTALLED_APPS = [
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.staticfiles',
    ],
    MIDDLEWARE = [
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
    ],
    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [
                os.path.join(BASE_DIR, 'templates'), # Here
            ],
            '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',
                ],
            },
        },
    ],
    STATIC_URL = '/static/',
    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, 'static'), # ...and HERE!
    ],
)

BASE_DIR = os.path.dirname(os.path.abspath(__file__)),中删除,,否则将其读为元组,

这样一定是:

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

最新更新