سؤال

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?

هل كانت مفيدة؟

المحلول

You can always do:

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

The reason this would work is, from the source code

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

and 2./24 in

datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS)

is perfectly valid.

Example:

>>> 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)
>>> 
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top