PyCharm 代码检查抱怨找不到模板文件,如何解决? [英] PyCharm code inspection complains template file not found, how to fix?

查看:62
本文介绍了PyCharm 代码检查抱怨找不到模板文件,如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 PyCharm 的新手,我正在尝试将它用于 Django 开发.我的应用程序的结构如下:

I'm new to PyCharm, and I'm trying to use it for Django development. My app is structured like this:

bs3app/
├── __init__.py
├── templates
│   └── home.html
├── urls.py
└── views.py

bs3app/views.py 中,我收到警告:

In bs3app/views.py, I get a warning:

找不到模板文件home.html"

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 视图可以正常工作.在项目的Django Support页面,Enable Django Support开启,Django项目根目录设置Manage script 值都正确.

The template file is there in bs3app/templates/home.html. The home view works correctly when I run the site. On the Django Support page of the project, Enable Django Support is on, and the Django project root, Settings and Manage script values are all correct.

那么,为什么我会收到警告?根据 this PyCharm doc page,我可以标记模板目录明确地然后警告消失,但为什么我必须?给定项目的 settings.py 文件,为什么 PyCharm 不能自动计算出来?

So, why am I getting the warning? As per this PyCharm doc page, I can mark the template directories explicitly and then the warning goes away, but why do I have to? Why can't PyCharm figure them out automatically, given the settings.py file of the project?

该项目位于 GitHub,如果您需要查看其他文件.

The project is on GitHub, if you need to see other files.

推荐答案

只需打开project view(view->tool windows -> project).右键单击您的 templates-folder -> 'mark directory as'-> Template directory

Just open the project view (view->tool windows -> project). There right-click on your templates-folder -> 'mark directory as'-> Template directory

这篇关于PyCharm 代码检查抱怨找不到模板文件,如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆