Python 尝试创建详细信息页时出错
我的模型中有两个类,如下所示:Python 尝试创建详细信息页时出错,python,django,Python,Django,我的模型中有两个类,如下所示: 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) ........ d
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})
我一直收到一个字段错误:
无法将关键字“d”解析为字段。选择包括:身份证、姓名、非营利组织、工资、职称
我是个大傻瓜,不知道怎么解决这个问题。我不知道为什么当d等于一个字段时,它不能将其解析为一个字段….输入错误:
e = get_object_or_404(executive, d=id)
应该是:
e = get_object_or_404(executive, id=id)
谢谢看起来它真的应该是“执行官”而不是“执行官”。作为一个傻瓜,小小的打字错误现在正折磨着我。