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

查看:175
本文介绍了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 中,我收到警告:

未找到模板文件"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支持页面上,启用Django支持已打开,并且 Django项目根目录设置管理脚本值都是正确的.

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.

那么,为什么我会收到警告?根据此PyCharm文档页面,我可以标记模板目录明确地然后警告消失,但是为什么我必须?给定项目的 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.

推荐答案

只需打开项目视图(视图->工具窗口->项目).在您的 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天全站免登陆