I am building a script that use the datetime module :
def workspace_detail(request, token):
yesterday = date.today() - timedelta(days=1)
tomorrow = date.today() - timedelta(days=1)
quicklink = f"{token}start_date={yesterday}&end_date={tomorrow}"
w_yesterday = quicklink
But I have this error
local variable 'date' referenced before assignment
I imported it every module from the datetime package
from datetime import datetime, date, timedelta
If I use datetime.today() it works, but I want to use the date.today() for my url.
Thanks
Are you using the word "date" as a variable anywhere else in your function or script?.
This happened to me and the fix was to rename any variable named "date" and only use that keyword for the date object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With