1

Django Error When Publishing in DateTimeField

 2 years ago
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

advertisements

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'

I am getting error while publishing worker role from Visual Studio 2013 with update 5. When i select worker role project and click on publish, it is showing me below error on pop up window and i am not able to move ahead: There was an error reflectin

Take Django errors when the client is not a web browser?

I'm building a Django web service that is called from an application. When it throws an exception, I can't see the Django debug page, and can't get to it because the calling application doesn't behave like a web browser (and I don't have control over

Spring MVC 415 error when publishing form

Getting 415 error when doing POST request. This is my form: <c:url value="/createOrUpdate" var="actionUrl"/> <form action="${actionUrl}" method="post" enctype="application/x-www-form-urlencoded"&g

Ubuntu Nginx 403 error when publishing form data including & lt; iframe & gt;

I have a Ubuntu Nginx server (using laravel forge to set it up) I am now getting 403 errors when posting form data including which I was not getting previously. The form is posted by a javascript button $('#my-form').submit(); if this is relevant. Ot

Get a timeout error when publishing data

js.I am trying to create a file upload using node.js and mongodb.I am getting timeout error in posting data.The code that i use is: app.post('/photos/new', function(req, res) { var photo = new Photo(); req.form.complete(function(err, fields, files) {

View django errors when using ajax

I want to use ajax in my invitation form. It is a simple form which is about posting email. I did the invitation form with the ajax but i could not show django specific error. For example, if i try to post the same email address, it should throw an e

First application of Django: error when creating sql tables from my models

I'm new in Python and I would to start some tutorial using Django. I would use PyCharm as IDE. So, I tried to create my start Django project. I use a Mac, Python 2.7.5 version, Django 1.7.5 version. I follow this tutorial to create my first Django ap

Django error when installing Graphite - settings.DATABASES is incorrectly configured. Please provide ENGINE

I am trying to install GRAPHITE on ubuntu. I follow the instructions in the blog. http://geek.michaelgrace.org/2011/09/how-to-install-graphite-on-ubuntu/ When I get to the part where I run the command..I get the below error. I have zero clue on how t

Authentication Error When Publishing Gracle to Nexus

I am using gradle v3.4 and trying to publish a jar file to nexus. Relevant portions of build.gradle and error are copied below: build.gradle repositories { maven { credentials { username project.properties['nexusUser'] password project.properties['ne

Get a JS error when publishing the site

Getting a: Error: ReferenceError: $ is not defined when I publish my website. Even though I have the JQuery lib added in the Layout page, and now also on the partialView that complains about not finding the JQuery lib This is how I reference it: <scr

Facebook Graph API error when publishing a scheduled message on the Business page

I am using Facebook php graph api and I've been trying to post a scheduled post to a business page but with no luck, However, I can successfully post a published status on the same page. I've read in the FB API, that to post a scheduled status I must

How to fix the 401 authentication error when publishing to the self-hosted NuGet server

I followed these instructions to host a NuGet Server (version 2.2.2) on our Intranet. It works great as far as listing the packages and retrieving them in VS 2012. But when I create a package using the Nuget Package Explorer and try to publish it I a

Django Error: when displaying two models in an html

I want to show 2 models (Input; Result) in one template html(Result): The error is "ResultView" is not defined. Please correct me if there is anything wrong below. Thanks in advance for your suggestion. Result - Views.py from result.models impor

Facebook PHP SDK v5 OAuth Connection error when publishing on page as page

I'm using the code below on my website to try and post a message on a Facebook page that I manage. I'm using the Facebook PHP SDK v5. Whenever I run the code I get directed to Facebook with an error window that says, "URL Blocked: This redirect faile

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK