![](/style/images/good.png)
![](/style/images/bad.png)
Django Error When Publishing in DateTimeField
source link: https://www.codesd.com/item/django-error-when-publishing-in-datetimefield.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Django Error When Publishing in DateTimeField
I am trying to post an entry into my Django model which has a DateTimeField
. Since i am using angular on my frontend, the date format that it posts to my Django View is of the format
Tue Jun 30 2015 00:00:00 GMT-0500 (CDT)
But Django will not allow me to post as the datetime format did not allow this format.
2015-05-23 18:48:08.543655
and it threw me this error:
[u"'Tue Jun 30 2015 00:00:00 GMT-0500 (CDT)' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]
So what do i use to get around this issue?
Call toUTCString()
on your Date
instance:
var d = new Date();
var n = d.toUTCString();
On the python side thats parsable with:
datetime.strptime("Tue, 22 Nov 2011 06:00:00 GMT", "%a, %d %b %Y %H:%M:%S %Z")
Also if you're working with django forms, have a look at the datetimefield documentation. You can find an explanation on how to set various formats there.
Related Articles
Error when publishing the worker role in VS 2013: There was an error reflecting the type 'Microsoft.Cct.AzureDiagnostics.ObjectModel.PublicConfig'
Take Django errors when the client is not a web browser?
Spring MVC 415 error when publishing form
Ubuntu Nginx 403 error when publishing form data including & lt; iframe & gt;
Get a timeout error when publishing data
View django errors when using ajax
First application of Django: error when creating sql tables from my models
Django error when installing Graphite - settings.DATABASES is incorrectly configured. Please provide ENGINE
Authentication Error When Publishing Gracle to Nexus
Get a JS error when publishing the site
Facebook Graph API error when publishing a scheduled message on the Business page
How to fix the 401 authentication error when publishing to the self-hosted NuGet server
Django Error: when displaying two models in an html
Facebook PHP SDK v5 OAuth Connection error when publishing on page as page
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK