Django server shows wrong time

I have a problem with my django server time, it is 2 hours late. I tried to find a solution but whatever i found (as How to change my django server time, or Django documentation) is not what I think I need.

Right now my computer's time is 23:14:37 When i write in bash date +%H:%M:%S I will get:

(python_env) bash-3.2$ date +%H:%M:%S
23:17:03

So I don't think this is my console problem.

But when I am running my server here is what I get:

(python_env) bash-3.2$ python3 manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
April 04, 2020 - 21:18:47
Django version 2.2.4, using settings 'myVote365.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

The time is now 2 hours late.

I have red that it could be because of wrong timezone, but I have my code similar to How to change my django server time

LANGUAGE_CODE = 'pl'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

What's more it worked perfectly fine just before I change my os to Windows, and to OS X again

Edit:

I changed USE_TZ to False, ran and closed the server, and again to True. And now although I still have a server 2 hour late. But from error:

Internal Server Error: /panel/
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 189, in _get_session
    return self._session_cache
AttributeError: 'SessionStore' object has no attribute '_session_cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 383, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: django_session

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/icookiez/Documents/praca/dla taty/myVote365/myVote365/audytor/views.py", line 26, in panel
    if 'auditor' in request.session and request.session['auditor']['logged'] is True:
  File "/usr/local/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 51, in __contains__
    return key in self._session
  File "/usr/local/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 194, in _get_session
    self._session_cache = self.load()
  File "/usr/local/lib/python3.7/site-packages/django/contrib/sessions/backends/db.py", line 43, in load
    s = self._get_session_from_db()
  File "/usr/local/lib/python3.7/site-packages/django/contrib/sessions/backends/db.py", line 34, in _get_session_from_db
    expire_date__gt=timezone.now()
  File "/usr/local/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 402, in get
    num = len(clone)
  File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 256, in __len__
    self._fetch_all()
  File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 1242, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 55, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/usr/local/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1100, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 99, in execute
    return super().execute(sql, params)
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 383, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: django_session

I got a working site.

Upvotes: 0

Views: 1689

Answers (2)

First step

I changed USE_TZ to False, ran and closed the server, and again to True. This allowed my side to load, but still had the wrong time.

Second step

I changed TIME_ZONE not to ‘PL’ as @jatrp5 suggested, but to 'Europe/Warsaw' as I read on this question. Using the zone name form Wikipedia. And now I have time I was wishing for.

Upvotes: 1

jatrp5
jatrp5

Reputation: 31

To match your bash time you should change the time zone to TIME_ZONE = 'PL'. The universal time zone (UTC) is two hours behind the Polish.

Upvotes: 0

Related Questions