in settings.py Datei konvertieren:Datumzeit-Anzeige und Zeitzone in django
TIME_ZONE = 'UTC'
USE_TZ = True
in models.py:
from django.utils import timezone
date = models.DateTimeField(default = timezone.now())
vor pytz, Datumsfeld in mysql pip installiert db als UTC-Zeit gespeichert, und Datum in der Front-End-Webseite als Ortszeit angezeigt. aber nach pip install pytz, datum feld in mysql db als UTC zeit gespeichert, zur gleichen zeit datum in der vorderseite webpage display als UTC zeit zu.
Was ist der Grund dafür? Wie stellt man sicher, dass nach pip install pytz, date-feld in mysql db als UTC zeit gespeichert, und datum in der vorderseite webpage display als localtime? BTW, welche Bibliothek ist einfacher als Pytz?
Ich behandle diese Website als globale Website, also TIME_ZONE nicht als eine bestimmte Zeitzone festgelegt. nicht wahr? – Scott
Siehe https://docs.djangoproject.com/en/1.11/topics/i18n/timezones/#default-time-zone-and-current-time-zone und https://docs.djangoproject.com/en/1.11/topics/i18n/timezones/# Zeitzone-aware-output-in-templates –
Vielen Dank, dieses Problem ist gelöst nach https://docs.djangoproject.com/de/1.11/topics/i18n/timezones/ . – Scott