【发布时间】:2020-07-14 17:00:33
【问题描述】:
即使文件存在,我也会收到此错误 - 为什么?
编辑:
补充编辑:
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)
它说我写的不够多,代码太多,没有描述。所以我打字是为了绕过这个错误。
【问题讨论】:
-
您没有提供足够的信息(没有 TEMPLATES 设置和 INSTALLED_APPS)。但我的上帝感觉 TEMPLATES 中的 APP_DIRS 设置设置为 False。
-
catalog在INSTALLED_APPS中吗? -
@AntonPomieshchenko 编辑它们
-
@dirkgroten 是的。