我是 PyCharm 的新手,我正在尝试使用它进行 Django 开发。我的应用程序结构如下:
bs3app/
├── __init__.py
├── templates
│ └── home.html
├── urls.py
└── views.py
在 bs3app/views.py
中,我收到一条警告:
Template file 'home.html' not found
源代码:
from django.shortcuts import render_to_response
def home(request):
return render_to_response('home.html')
模板文件位于 bs3app/templates/home.html
中。当我运行站点时,home
View 工作正常。在项目的Django Support页面,Enable Django Support是开启的,Django project root,Settings和 Manage script 值都是正确的。
那么,为什么我会收到警告?根据 this PyCharm doc page ,我可以显式标记模板目录,然后警告消失,但为什么我必须?给定项目的 settings.py
文件,为什么 PyCharm 不能自动找出它们?
项目在GitHub , 如果您需要查看其他文件。
最佳答案
只需打开项目 View
( View ->工具窗口->项目)。右键单击您的 templates
-folder -> 'mark directory as'-> Template directory
关于django - PyCharm 代码检查提示找不到模板文件,如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20873625/