import module == from module import *?

后端 未结 3 1972
自闭症患者
自闭症患者 2021-01-16 12:06

I had a problem with the Django tutorial so I asked a question here. No-one knew the answer, but I eventually figured it out with help from Robert. Python seems to be trea

3条回答
  •  有刺的猬
    2021-01-16 12:46

    The problem in the latter snippet is with this part of your code:

    return (self.pub_date() == datetime.date.today())
    

    self.pub_date contains a datetime.datetime instance. It's not callable like that. For example:

    >>> import datetime
    >>> d = datetime.datetime.now()
    >>> d()
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: 'datetime.datetime' object is not callable
    >>>
    

    If you want to compare only the date, you should call it thus:

    return (self.pub_date.date() == datetime.date.today())
    

提交回复
热议问题