1
我有一個Django應用程序,我用uWSGI和nginx設置Django和我的web服務器。我有一個設置訪問時間爲我的文件中的函數,這是我的函數:Django時間無法正常工作
from shutil import move
from time import mktime
from os import utime
def spool(self, time=None):
if time:
try:
time = mktime(time.timetuple())
utime(path(self.tempdir)/path(self.filename), (time, time))
except (error, AttributeError, OverflowError, ValueError):
raise InvalidTimeError
try:
move(path(self.tempdir)/path(self.filename),
path(self.spool_dir)/path(self.filename))
except IOError:
raise NoSpoolPermissionError
當我運行與Python命令該功能的訪問時間是正確的:
[email protected]:~# stat /var/spool/asterisk/outgoing/tmp_4BmDa.call
File: `/var/spool/asterisk/outgoing/tmp_4BmDa.call'
Size: 56 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 561550 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2013-08-21 11:27:30.000000000 +0430
Modify: 2013-08-21 11:27:30.000000000 +0430
Change: 2013-08-21 11:24:00.142143170 +0430
Birth: -
但是當我運行在我的Django應用程序函數的輸出是:
[email protected]:~# stat /var/spool/asterisk/outgoing/tmp_4BmDa.call
File: `/var/spool/asterisk/outgoing/tmp_4BmDa.call'
Size: 242 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 561542 Links: 1
Access: (0666/-rw-rw-rw-) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2013-08-21 21:15:00.000000000 +0430
Modify: 2013-08-21 21:15:00.000000000 +0430
Change: 2013-08-21 11:44:42.982093206 +0430
Birth: -
正如你所看到的訪問時間是< < 2013年8月21日21點15分零零秒>>但它必須是< < 2013-08-21 11:44:42 >>我不知道發生了什麼。 Linux的date命令的輸出是:
[email protected]:~# date
Wed Aug 21 11:44:55 IRDT 2013
和Python的datetime輸出:在設定爲合適的值Web服務器的conf和Django配置
>>> datetime.datetime.now()
datetime.datetime(2013, 8, 21, 11, 45, 57, 886360)
檢查webserver conf和django設置中的時區設置是否設置爲適當的值。 – Rohan
非常感謝,它解決了這個問題 – nim4n