我的模型中有两个类,如下:
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”解析为字段。选择是:身份证,姓名,非营利组织,工资,职称
我是一个巨大的菜鸟,无法弄清楚如何解决这个问题。我不知道为什么当d等于一个字段时它无法将其解析为字段....
答案 0 :(得分:1)
错字:
e = get_object_or_404(executive, d=id)
应该是:
e = get_object_or_404(executive, id=id)