问题
把html文件放在templates目录中,在views.py中使用return render(request, 'register.html')
时,请求该页面,一直报TemplateDoesNotExist
解决
看了网上的一些解决方案,原因是Python Path中没有我的文件目录,但是其实我在setting.py文件中已经添加了sys.path.insert(0, os.path.join(BASE_DIR, "templates"))
,从上面截图也可以看出,Python Path中是有templates目录的。
最终,在setting.py文件中,TEMPLATES的DIRS添加了templates目录,至此,问题解决,请求成功
TEMPLATES = [
{
'BACKEND': 'django.template.backends.jinja2.Jinja2',
'DIRS': [
'./meiduo_mall/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',
],
'environment': 'meiduo_mall.utils.jinja2_env.jinja2_environment',
},
},
...
]