Another weird behavior i encountered and not really sure why it happens…
I won’t completely write what i am doing, basically i have one view for 2 cases: default case when search takes today date by default if nothing is specified , and second is where i specify what date i want to see and get a query …
So here is urls.py:
url(r'^$', index),
url(r'^(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<change>prev|next)/$', index),
And here is views.py:
def index(request, month = date.today().month, day = date.today().day, change=None):
# apply next / previous change
if change in ("next", "prev"):
now, mdelta = date(date.today().year, int(month), int(day)), timedelta(days=1)
if change == "next": mod = mdelta
elif change == "prev": mod = -mdelta
month, day = (now+mod).timetuple()[1:3]
someData= SomeModel.objects.filter(
date__exact = date(date.today().year, int(month), int(day))
)
return render_to_response('someapp_index.html',RequestContext(request,{'next':request.path, 'someData':someData, 'month': month, 'day':day}))
The thing which occurs is that for some reason when 24 hours pass and next day comes, someData does not update to next day. So for example if today is 15 and 24 hours pass, and already is 16 , then you expect on refresh that someData will filtered by 16 of January but instea it is still filtered by 15 because month and day stays the same from the moment i started or restarted uwsgi server…. ?!?!?!?!?
I tried putting those date.today().dat/month as variables passed in url file , and it had absolutely the same effect ….
Am i the only one with this problem , and it should not occur , or it should behave like this and you can’t put date.today() objects ?
Yes, your month/day values are initialized on server init.
Set them to
Noneif you want defaults, and calldate.today()in your view if they areNone.Passing
date.today()as an argument to a function will force it to be evaluated. It is the same as passing the function one specific value.Change to