即使文件存在,我也会出现此错误-为什么
编辑:
附加编辑:
from django.shortcuts import render
# Create your views here.
from catalog.models import Book, Author, BookInstance, Genre
def index(request):
"""View function for home page of site."""
# Generate counts of some of the main objects
num_books = Book.objects.all().count()
num_instances = BookInstance.objects.all().count()
# Available books (status = 'a')
num_instances_available = BookInstance.objects.filter(status__exact='a').count()
# The 'all()' is implied by default.
num_authors = Author.objects.count()
context = {
'num_books': num_books,
'num_instances': num_instances,
'num_instances_available': num_instances_available,
'num_authors': num_authors,
}
# Render the HTML template index.html with the data in the context variable
return render(request, 'index.html', context=context)
它说我写得不够,代码太多,没有描述。因此,我正在键入以绕过此错误
您的设置看起来是正确的,只是尽量不提供目录。这可能就是问题所在。这是我的一个项目的设置
可能发生的情况是
DIRS
文件路径可能没有指向您想要的位置。您可以在Django控制台中尝试此操作激活您的虚拟环境
$ source venv/bin/activate
然后运行python manage.py shell
在外壳中:
输出是否指向您期望的位置
======编辑
我看到Django正在/catalog/上寻找你的模板,实际上,你的模板位于app/catalog/templates/中,因此你的DIRS指令没有指向正确的路径
如果删除
DIRS
中的目录,Django将遍历名为templates
的文件夹的目录目录,并找到您的index.html
相关问题 更多 >
编程相关推荐