Django报错TypeError: descriptor ‘format’ for ‘str’ objects doesn’t apply to a ‘WindowsPath’ object
原因:str字符串写法异常

更改为:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
# 'DIRS': [os.path.join(BASE_DIR, 'templates')],
'DIRS': str(BASE_DIR / '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',
],
},
},
]

本文介绍了一种常见的Django框架错误,即TypeError提示描述符‘format’对于‘str’对象不适用‘WindowsPath’对象的情况。通过将路径配置从os.path.join更改为使用pathlib的表达方式,解决了这一问题。

2174

被折叠的 条评论
为什么被折叠?



