我的模型中有两个类,如下所示:
from django.db import models
class nonprofit(models.Model):
organization = models.CharField(max_length=200)
city = models.CharField(max_length=200)
website = models.URLField(max_length=120, blank=True)
........
def __unicode__(self):
return self.organization
class executive(models.Model):
nonprofit = models.ForeignKey(nonprofit)
name = models.CharField(max_length=200)
title = models.CharField(max_length=200)
salary = models.PositiveIntegerField()
def __unicode__(self):
return self.name我的视图如下所示:
from django.shortcuts import render_to_response, get_object_or_404
from nonprofit.models import executive
def index(request):
executives = executive.objects.all()
return render_to_response('nonprofit/index.html', {'executives': executives})
def detail(request, id):
e = get_object_or_404(executive, d=id)
return render_to_response('nonprofit/detail.html', {'executives': e})我一直收到FieldError:无法将关键字'd‘解析为字段。选项包括: id、姓名、非盈利组织、薪资、职称
我是个大菜鸟,不知道怎么解决这个问题。我不知道为什么当d等于一个字段时,它不能将它解析为一个字段...
发布于 2010-12-16 07:50:59
打字错误:
e = get_object_or_404(executive, d=id)应该是:
e = get_object_or_404(executive, id=id)https://stackoverflow.com/questions/4456169
复制相似问题