Timezone works locally, but not in pythonanywhere (DJango)

0

I have a queryset that lists all sales today:

from django.utils import timezone

class VentaToday(ListView):
    queryset = Venta.objects.filter(fecha=timezone.now()).order_by('-id')
    template_name = 'venta/venta_today.html'

In local, this works correctly but in production (Pythonanywhere) the sales of the previous day keep appearing. To fix it, I have to go to the pythonanywhere panel and click on the ** reload ** button to solve the problem or update the page and then the previous day's sales disappear.

I have tried changing the server time:

And this is the settings of my settings.py

LANGUAGE_CODE = 'es-pe'

TIME_ZONE = 'America/Lima'

USE_I18N = True

USE_L10N = True

USE_TZ = True

Is it a cache problem on the server? or something am I doing wrong? since in local I do not have that problem.

    
asked by Piero Pajares 24.03.2018 в 15:08
source

1 answer

0

Solved: First I had to download pytz because the server when doing maintenance changes the time zone.

pip install pytz

After passing 12 the same did not update the list ... then I had to replace my queryset and returning the list with the pytz filter:

from datetime import datetime
import pytz

class VentaToday(ListView):
    def get_queryset(self):
        return Venta.objects.filter(fecha=datetime.now(pytz.timezone('America/Lima'))).order_by('-id')
    template_name = 'venta/venta_today.html' 

Now, after 12AM, restart sales again! I hope I can help someone if something similar happens.

    
answered by 31.03.2018 / 15:58
source