nextdoordoc
nextdoordoc

Reputation: 1767

Django - ValueError: Invalid timezone: u'Asia/Seoul ROK'

I had a problem with template tag "timezone" for a while.

## template
{% load tz %}
{% timezone 'Asia/Seoul ROK' %}
    {{ reservation.datetime|date:"G:i A e" }}
{% endtimezone %}

I already write USE_TZ = True / TIME_ZONE = 'Asia/Seoul ROK' And I also installed pytz module and move the module on to my project (I am developing django on eclipse pydev.)

And whenever I run the project i face the error below.

Invalid timezone: u'Asia/Seoul ROK'

How could I solve this problem? Thanks in advance.

Upvotes: 0

Views: 1293

Answers (2)

OrionMelt
OrionMelt

Reputation: 2601

Try Asia/Seoul maybe?

There is no such timezone as Asia/Seoul ROK in pytz.all_timezones.

Edit: So Asia/Seoul gives you the same error.

Maybe pytz isn't getting imported.

This is where the error comes from in django/utils/timezone.py:

try:
    import pytz
except ImportError:
    pytz = None
...
...
if isinstance(timezone, tzinfo):
    _active.value = timezone
elif isinstance(timezone, six.string_types) and pytz is not None:
    _active.value = pytz.timezone(timezone)
else:
    raise ValueError("Invalid timezone: %r" % timezone)

This most probably means pytz is None after all and you get the error.

Does any other timezone work? If not, then pytz import must be the problem.

Upvotes: 3

Arundas R
Arundas R

Reputation: 770

I am not much familiar with pytz. But i think you should look at this

Python - Pytz - List of Timezones?

Try Asia/Seoul

I tried it in python shell and got same error

>>> a = pytz.timezone("Asia/Seoul ROK")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pytz-2014.7-py2.7.egg/pytz/__init__.py", line 180, in timezone

pytz.exceptions.UnknownTimeZoneError: 'Asia/Seoul ROK'

Upvotes: 0

Related Questions