我正试着和Django联系。只有Flutter和Django看起来很好,没有错误。但是,当我试图将两者结合在一起时,会出现一个错误:
TemplateDoesNotExist at /accounts/
这是问题的原因
from django.shortcuts import render, HttpResponse
def home(request):
return render(request, '../screens/login_screen.dart')它说目录不存在。

正如您在上面看到的,目录是存在的。有人能帮忙有什么问题吗?
模板:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
},
]发布于 2020-02-01 15:08:43
我能看到的是屏幕文件夹在根目录上,而不是在accounts文件夹中,它是self的。为此,必须在设置内的模板配置中显式提及。您必须提到"BASE_DIR,模板所在的文件夹的名称“。这是怎么写的。
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'screens')],
'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',
],
},
},
]其次,您必须以这种方式在视图中给出文件的路径。
return render(request, 'screens/login_screen.dart', context)希望这能有所帮助。
https://stackoverflow.com/questions/60017343
复制相似问题