Python django时间无法正常工作
我有一个django应用程序,我用uWSGI和nginx设置django和我的web服务器。我有一个设置文件访问时间的函数,这是我的函数:Python django时间无法正常工作,python,django,linux,time,Python,Django,Linux,Time,我有一个django应用程序,我用uWSGI和nginx设置django和我的web服务器。我有一个设置文件访问时间的函数,这是我的函数: from shutil import move from time import mktime from os import utime def spool(self, time=None): if time: try: time = mktime(time.timetuple()) u
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命令运行此函数时,访问时间是正确的:
root@demo:~# 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应用程序中运行该函数时,输出为:
root@demo:~# 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: -
root@demo:~# date
Wed Aug 21 11:44:55 IRDT 2013
正如你所看到的,访问时间是有限的,但必须是有限的,我不知道发生了什么。
linux日期命令输出为:
root@demo:~# 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: -
root@demo:~# date
Wed Aug 21 11:44:55 IRDT 2013
和python日期时间输出:
>>> datetime.datetime.now()
datetime.datetime(2013, 8, 21, 11, 45, 57, 886360)
检查webserver conf中的时区设置,并将django设置设置为适当的值
wsgi/django环境中的时间将受到这些配置文件中时区设置的影响。检查webserver conf中的时区设置,并将django设置设置为适当的值
wsgi/django环境中的时间将受到这些配置文件中时区设置的影响。检查Web服务器配置中的时区设置,并将django设置设置为适当的值。非常感谢,它解决了问题检查Web服务器配置中的时区设置,并将django设置设置为适当的值。非常感谢,它解决了问题