2

I am using Django registration app that sends email to the registered users for confirmation. The default activation window is

ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window; 

I want to keep the activation link open for two hours. After which, the link will be invalid. how can I achieve this?

4

1 回答 1

2

你总是可以这样做:

ACCOUNT_ACTIVATION_DAYS = 2./24 #(2 hours, or 0.0833)

这会起作用的原因是,从源代码

expiration_date = datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS)

并且2./24

datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS)

是完全有效的。

例子:

>>> datetime.datetime.now() 
datetime.datetime(2014, 3, 25, 14, 3, 40, 137723)
>>> datetime.datetime.now() + datetime.timedelta(days=2./24)
datetime.datetime(2014, 3, 25, 16, 3, 53, 521675)
>>> 
于 2014-03-25T18:03:02.783 回答