Home > Net >  Comments DateTimeField() Django
Comments DateTimeField() Django

Time:05-12

I'm trying to build a comments section in my website, and I'm pretty much done, but I'm trying to display the time that it was posted, but it keeps displaying the wrong time.

This is my code in my models.py Posts class:

date = models.DateTimeField(default=timezone.now)

I know that the database recognizes something is wrong because it shows me this message:

(https://i.stack.imgur.com/NYKRS.jpg)

but I don't know how to fix it. Can someone please help me? Thanks!

P.S: I know it says it's behind, but at the time this screenshot was taken, the date was 5/10, not 5/11.

CodePudding user response:

check your "settings.py" and rewrite TIME_ZONE

How to set the timezone in Django?

https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

and I recommend to fix code like this. It doesn't have to import timezone

date = models.DateTimeField(auto_now_add=True)
  • Related