我有一个查询集来列出今天的销售额
from django.utils import timezone
class VentaToday(ListView):
queryset = Venta.objects.filter(fecha=timezone.now()).order_by('-id')
template_name = 'venta/venta_today.html'
在本地,这可以正常工作,但在生产(Pythonanywhere)中,前一天的销售量会继续出现。要修复它,我必须转到 pythonanywhere 面板并单击 ** reload ** 按钮来解决问题。
我更改了服务器时间:
django项目的配置:
LANGUAGE_CODE = 'es-pe'
TIME_ZONE = 'America/Lima'
USE_I18N = True
USE_L10N = True
USE_TZ = True
是服务器缓存问题吗?还是我做错了什么?
更新 配置 WSGI:
# +++++++++++ DJANGO +++++++++++
# To use your own django app use code like this:
import os
import sys
os.environ["TZ"] = "America/Lima"
#
## assuming your django settings file is at '/home/dnicosventas/mysite/mysite/settings.py'
## and your manage.py is is at '/home/dnicosventas/mysite/manage.py'
path = '/home/dnicosventas/dnicos-ventas'
if path not in sys.path:
sys.path.append(path)
#
os.environ['DJANGO_SETTINGS_MODULE'] = 'DnicosVentas.settings'
#
## then, for django >=1.5:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
## or, for older django <=1.4
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
和我的控制台:
export TZ="/usr/share/zoneinfo/America/Lima"
即便如此,在上午 12 点之后,昨天的销售仍然出现,直到我单击 pythonanywhere 面板中的重新加载按钮。
视图.py:
class VentaToday(ListView):
today = datetime.now(pytz.timezone('America/Lima'))
queryset = Venta.objects.filter(fecha=today).order_by('-id')
template_name = 'venta/venta_today.html'