【发布时间】:2016-02-11 06:57:34
【问题描述】:
在 django 设置过程中,我遇到了以下错误
引发 TypeError("'%s' 是此函数的无效关键字参数" % list(kwargs)[0])
TypeError: 'pub_date' 是此函数的无效关键字参数
Models.py
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
import datetime
from django.utils import timezone
# Create your models here.
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
@python_2_unicode_compatible # only if you need to support Python 2
class Question(models.Model):
# ...
def __str__(self):
return self.question_text
@python_2_unicode_compatible # only if you need to support Python 2
class Choice(models.Model):
# ...
def __str__(self):
return self.choice_text
class Question(models.Model):
# ...
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
【问题讨论】: