开发者

Django - replacing year in DateTimeField

开发者 https://www.devze.com 2023-03-19 05:07 出处:网络
With this:开发者_StackOverflow mb = self.birthdate.replace(year=date.today.year) It gives this: Caught AttributeError while rendering: \'builtin_function_or_method\' object has no attribute \'year\'

With this:

开发者_StackOverflow mb = self.birthdate.replace(year=date.today.year)

It gives this:

Caught AttributeError while rendering: 'builtin_function_or_method' object has no attribute 'year'

It is possible to replace year?


The correct line is:

mb = self.birthdate.replace(year=date.today().year)

date.year is a method not a attribute

datetime.date.today

0

精彩评论

暂无评论...
验证码 换一张
取 消