我收到 TemplateDoesNotExistError
我是Django开发的新手,已经花费了数小时试图解决此问题,但没有成功。谁能指导我?
我的项目是basilweb,而我在该项目中的应用程序是basilapp。 如果会话中不存在“ gocker_setting ”,我需要显示一个屏幕来吸引用户。
向用户询问此gocker_setting的表单正确显示,并且我能够在我的视图中正确检索该值。但是,当我下次尝试在获取值后渲染屏幕时,在/ genie / gocker 处出现了 TemplateDoesNotExistError。
模板加载器验尸:
模板加载器事后检查
Django尝试按以下顺序加载这些模板:
使用引擎django:
django.template.loaders.filesystem.Loader: /home/sekhar/development/python-code/basilweb/basilapp/templates/{} (Source does not exist)
django.template.loaders.app_directories.Loader: /home/sekhar/development/python-code/basilweb/python-env/lib/python3.5/site-packages/django/contrib/admin/templates/{} (Source does not exist)
django.template.loaders.app_directories.Loader: /home/sekhar/development/python-code/basilweb/python-env/lib/python3.5/site-packages/django/contrib/auth/templates/{} (Source does not exist)
django.template.loaders.app_directories.Loader: /home/sekhar/development/python-code/basilweb/basilapp/templates/{} (Source does not exist)
这是我的设置的详细信息
#settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'basilapp',
]
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',
],
},
},
]
# my directory structure
basilweb
basilapp
templates
genie
getgockersetting.html
gocker.html
# basilweb/url.py
urlpatterns = [
path('genie/', include('basilapp.genie.urls')),
path('saras/', include('basilapp.saras.urls')),
path('admin/', admin.site.urls),
path('accounts/', include('django.contrib.auth.urls')),
]
# bailapp/genie/urls.py
urlpatterns = [
path('index', views.index, name='genie_index'),
path('gocker', views.gocker, name='genie_gocker'),
]
# basilapp/genie/views.py
@login_required(login_url='/accounts/login/')
def gocker(request):
gocker_setting = None
if "gocker_setting" in request.session:
gocker_setting = request.session["gocker_setting"]
else:
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = forms.GockerSettingForm(request.POST)
# check whether it's valid:
if form.is_valid():
gocker_setting = form.cleaned_data['gocker_setting']
request.session["gocker_setting"] = gocker_setting
if gocker_setting is None:
form = forms.GockerSettingForm()
return render(request, 'genie/getgockersetting.html', {'form': form})
else:
# gocker setting is present
# do further processing
# ****** This is where I get the ERROR ********
return render('/genie/gocker.html', {})