mfogel / django-timezone-field

A Django app providing DB, form, and REST framework fields for zoneinfo and pytz timezone objects.
BSD 2-Clause "Simplified" License
397 stars 95 forks source link

Requested setting USE_DEPRECATED_PYTZ, but settings are not configured. #125

Closed skbohra closed 4 months ago

skbohra commented 7 months ago

With django == 4.2.10 , getting this error, when configuring django-celery-beat which uses django-timezone-field


from .models import (ClockedSchedule, CrontabSchedule, IntervalSchedule,
  File "/home/humanoid/code/parikar-v1/devenv/lib/python3.10/site-packages/django_celery_beat/models.py", line 9, in <module>
    import timezone_field
  File "/home/humanoid/code/parikar-v1/devenv/lib/python3.10/site-packages/timezone_field/__init__.py", line 1, in <module>
    from timezone_field.fields import TimeZoneField
  File "/home/humanoid/code/parikar-v1/devenv/lib/python3.10/site-packages/timezone_field/fields.py", line 5, in <module>
    from timezone_field.backends import TimeZoneNotFoundError, get_tz_backend
  File "/home/humanoid/code/parikar-v1/devenv/lib/python3.10/site-packages/timezone_field/backends/__init__.py", line 5, in <module>
    USE_PYTZ_DEFAULT = getattr(conf.settings, "USE_DEPRECATED_PYTZ", VERSION < (4, 0))
  File "/home/humanoid/code/parikar-v1/devenv/lib/python3.10/site-packages/django/conf/__init__.py", line 102, in __getattr__
    self._setup(name)
  File "/home/humanoid/code/parikar-v1/devenv/lib/python3.10/site-packages/django/conf/__init__.py", line 82, in _setup
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting USE_DEPRECATED_PYTZ, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
mfogel commented 4 months ago

Hi @skbohra, I don't think this is an issue with this package. The error message there explains that

settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings

Here's a stack overflow that is from someone running into the same problem https://stackoverflow.com/a/50043590