Python——Django_关于Django3.1模板路径问题
使用Django3.1在pycharm新建项目时发现查找目录从原来的OS变为了pathlib
# 3.1之前 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) #3.1 BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
但是关于templates的dir没有改变,直接运行会报错,需要做一下修改
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [BASE_DIR.joinpath('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', ], }, }, ]

浙公网安备 33010602011771号