pub_date在Django教程错误中无效

时间:2013-02-06 07:23:23

标签: python django web-applications web-application-design

C:\mysite>python manage.py shell
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from polls.models import Poll,Choice
>>> Poll.objects.all()
[]
>>> import django
>>> from django.utils import timezone
>>> p= Poll(question="what's new?",pub_date= timezone.now())
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Python27\lib\site-packages\django\db\models\base.py", line 367, in __init__
    raise TypeError("'%s'is an invalid keyword argument for
                          this function"%kwargs.keys()   [0])
TypeError: 'pub_date' is an invalid keyword argument for this function

2 个答案:

答案 0 :(得分:2)

检查您的models.py可能您错误输入了pub_date日期时间字段

答案 1 :(得分:1)

有点晚了,但我也有这个问题,我找到了答案。将yor models.py文件更改为:

from django.db import models

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)