Search code examples
pythondjangotimezonepythonanywheregmt

how to setup django timezone in pythonanywhere


I have just deployed my django website to pythonanywhere and I have noticed that it uses a different timezone than the one which my local server is using.

I have an article model which contains a datetime field

class Article(models.Model):

    id=models.AutoField(primary_key=True)
    title=models.CharField(max_length=100,null=False,blank=False)
    category=models.ForeignKey(Category,null=False,blank=False)
    date=models.DateTimeField(auto_now_add=True)
    content = models.TextField(null=False, blank=False)
    resume=models.CharField(null=False,blank=False,max_length=400)
    image = models.FileField(blank=True)

I tried adding an article which was supposed to be saved at 13/07/2018 22:20, but is was saved at 13/07/2018 16:20

It seems that my website is hosted in another country which uses a different timezone, as my current timezone is GMT+1

Any help would be appreciated


Solution

  • I solved the issue by manually setting the time_zone in settings.py

    TIME_ZONE='Africa/Casablanca'