我在Django中创建网站时遇到了本地错误
from django.shortcuts import render, get_object_or_404
from .models import Board
from django.http import HttpResponse
# Create your views here.
def home(request):
boards = Board.objects.all()
return render(request, 'home.html', {'boards' : boards})
def board_topics(request,pk):
board = get_object_or_404(board, pk=pk)
return render(request,"topics.html",{'board' : board})
boards = Board.objects.all()
return render(request, 'home.html', {'boards' : boards})
答案 0 :(得分:4)
尝试更改
board = get_object_or_404(board, pk=pk)
到
board = get_object_or_404(Board, pk=pk)
传递给get_object_or_404()的第一个参数是Class。来自docs
班 从中获取对象的Model类,Manager或QuerySet实例。