在Django/Python应用程序中不存在模板

2024-04-24 06:24:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用PyCharm运行Django应用程序,但出现以下错误:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 1.7.1
Python Version: 2.7.14
Installed Applications:
('django_admin_bootstrapped',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'compressor',
'menu',
'django_extensions',
'estabelecimento',
'bootstrap3',
'django_autocomplete',
'easy_select2',
'daterange_filter',
'qrcode')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')

Template Loader Error:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
C:\Users\Marcos\PycharmProjects\japedi\django_admin_bootstrapped\templates\index.html (File does not exist)
C:\Python27\lib\site-packages\django\contrib\admin\templates\index.html (File does not exist)
C:\Python27\lib\site-packages\django\contrib\auth\templates\index.html (File does not exist)
C:\Python27\lib\site-packages\rest_framework\templates\index.html (File does not exist)
C:\Python27\lib\site-packages\compressor\templates\index.html (File does not exist)
C:\Python27\lib\site-packages\django_extensions\templates\index.html (File does not exist)
C:\Users\Marcos\PycharmProjects\japedi\bootstrap3\templates\index.html (File does not exist)
C:\Users\Marcos\PycharmProjects\japedi\daterange_filter\templates\index.html (File does not exist)
C:\Users\Marcos\PycharmProjects\japedi\qrcode\templates\index.html (File does not exist)



Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
137.                 response = response.render()
File "C:\Python27\lib\site-packages\django\template\response.py" in render
103.             self.content = self.rendered_content
File "C:\Python27\lib\site-packages\django\template\response.py" in rendered_content
78.         template = self.resolve_template(self.template_name)
File "C:\Python27\lib\site-packages\django\template\response.py" in resolve_template
54.             return loader.select_template(template)
File "C:\Python27\lib\site-packages\django\template\loader.py" in select_template
194.     raise TemplateDoesNotExist(', '.join(not_found))

Exception Type: TemplateDoesNotExist at /
Exception Value: index.html

项目中有一些名为模板的目录。对于每个特定的应用程序,其中都有一个文件夹模板。有人能帮我吗?有一个版本在生产环境中使用linux在数字海洋中运行良好。我正在尝试在我的计算机上运行windows 10。在

我试着把脏东西放进去设置.py,但没有逗号,用“=”代替“:”,没有成功。我的已安装应用程序部分如下:

^{pr2}$

我需要和索引.html根文件夹中的文件?因为我只有索引.wsgi. 在

Project Structure and views.py


Tags: djangoindexlibpackageshtmlsitenottemplate
1条回答
网友
1楼 · 发布于 2024-04-24 06:24:35

一些事情会导致这种情况。在

  1. 如果试图加载的html文件位于项目根目录下的templates文件夹中,则需要确保可以找到它。在

去你的设置.py,然后按如下方式设置“DIRS”。在

'DIRS': [os.path.join(BASE_DIR, 'templates')],
  1. 如果你想要的文件在应用程序的模板目录中,那么 确保应用程序位于设置.py在

这最后的想法是一个很长的机会,不应该是一个问题,但如果以上两个都是正确的,试试这个。在

我注意到不久前,如果安装的应用程序列表中的最后一个应用程序后面没有逗号,我可能会在PyCharm中得到这个错误。在

奇怪的是,如果我添加了逗号并让应用程序运行,我可以删除逗号,它仍然可以工作。在

我不认为这种情况还会发生,但是如果其他方法都失败了,那就去看看吧。在

-理查德

相关问题 更多 >