首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试创建详细信息页面时出错

尝试创建详细信息页面时出错
EN

Stack Overflow用户
提问于 2010-12-16 07:49:05
回答 1查看 828关注 0票数 0

我的模型中有两个类,如下所示:

代码语言:javascript
复制
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

我的视图如下所示:

代码语言:javascript
复制
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等于一个字段时,它不能将它解析为一个字段...

EN

回答 1

Stack Overflow用户

发布于 2010-12-16 07:50:59

打字错误:

代码语言:javascript
复制
e = get_object_or_404(executive, d=id)

应该是:

代码语言:javascript
复制
e = get_object_or_404(executive, id=id)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4456169

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档