DATE FORMAT ISSUE AGAIN.

305 views
Skip to first unread message

mralokkp

unread,
Mar 14, 2007, 10:21:12 AM3/14/07
to Django users
Hi All
Why Django Can't understand the supplied arguments.Why the code is too
rigid !

Case is this
XXXXXXX | date "F J Y"

It should read in the format that i choosen but instead of this gives
this error
TemplateSyntaxError at /mypage/
Could not parse the remainder: | date "F J Y"
Request Method: GET
Request URL: http://127.0.0.1:8000/mypage/
Exception Type: TemplateSyntaxError
Exception Value: Could not parse the remainder: | date "F J Y"

Even I followed the from this post itself. But Unable to do. could any
body tell what the problem exactly.

Even I tryed to import the file name dateformat.py from utils
but still stuck at the same point.

Help
Regards
Alok Tiwari

mail....@gmail.com

unread,
Mar 14, 2007, 10:34:28 AM3/14/07
to Django users
Just like it told you: Syntax error.

You want
{{ XXXXXXXX | date:"F J Y" }}
You missed the colon.

mralokkp

unread,
Mar 14, 2007, 10:45:22 AM3/14/07
to Django users
Thanks for the quickest reply
But the problem remains the same
TemplateSyntaxError at /registration/
Could not parse the remainder: | date: "F j Y"
Request Method: GET
Request URL: http://127.0.0.1:8000/registration/
Exception Type: TemplateSyntaxError
Exception Value: Could not parse the remainder: | date: "F j Y"
Exception Location: c:\Python24\Lib\site-packages\django\template
\__init__.py in __init__, line 556


On Mar 14, 7:34 pm, "bax...@gretschpages.com" <mail.bax...@gmail.com>
wrote:

Tim Chase

unread,
Mar 14, 2007, 10:49:28 AM3/14/07
to django...@googlegroups.com
> Case is this
> XXXXXXX | date "F J Y"
>
> It should read in the format that i choosen but instead of this gives
> this error
> TemplateSyntaxError at /mypage/
> Could not parse the remainder: | date "F J Y"

I've been bitten by this one several times. I haven't seen any
notes to the effect, but for some reason, the template parser
doesn't seem like extra whitespace. You'll also want to separate
your "date" from its argument with the colon:

fails: XXXX | date "F J Y"
works: XXXX|date:"F J Y"

I'll agree that whitespace makes it more readable, and that it
would be nice if the template engine was a little more forgiving.

But fortunately, it's an easy fix to just remove the whitespace.

Perhaps a little caveat about whitespace at

http://www.djangoproject.com/documentation/templates/#filters

would help reduce confusion?

-tkc


mralokkp

unread,
Mar 14, 2007, 10:54:14 AM3/14/07
to Django users
Thanks for that TIM A LOT
But stuck again

AttributeError at /registration/
'FormFieldWrapper' object has no attribute 'month'
Request Method: GET
Request URL: http://127.0.0.1:8000/registration/
Exception Type: AttributeError
Exception Value: 'FormFieldWrapper' object has no attribute 'month'
Exception Location: c:\Python24\Lib\site-packages\django\utils
\dateformat.py in F, line 123

mralokkp

unread,
Mar 14, 2007, 2:05:19 PM3/14/07
to Django users
HELP PLZZ

mail....@gmail.com

unread,
Mar 14, 2007, 2:20:05 PM3/14/07
to Django users
I don't know what you're trying to format, but is it actually a
datetime field?

Tim Chase

unread,
Mar 14, 2007, 2:28:57 PM3/14/07
to django...@googlegroups.com
> Thanks for that TIM A LOT

glad to help

> But stuck again
>
> AttributeError at /registration/
> 'FormFieldWrapper' object has no attribute 'month'

Well, somewhere in your code, you're asking for the "month"
attribute of an object. And that object doesn't have a "month"
property, so it raises the AttributeError exception.

This might stem from assigning a non-date value to a DateField
value, and then trying to read it back. Or it might stem from
assigning None to such an attribute (though IIRC, that raises
something like "'NoneType' object has no attribute 'month'". Or
you might be passing something that's a non-date to a "date" filter.

-tkc


James Bennett

unread,
Mar 14, 2007, 3:58:10 PM3/14/07
to django...@googlegroups.com
On 3/14/07, mralokkp <mral...@gmail.com> wrote:
> Could not parse the remainder: | date: "F j Y"

No spaces before or after the bar, no spaces before or after the colon:

{{ somvar|date:"F j y" }}

--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

mralokkp

unread,
Mar 15, 2007, 1:58:56 AM3/15/07
to Django users
Thanks James but the spaces had been removed
If Spaces it gives template error.
If not it gives the former error
says

AttributeError at /registration/
'FormFieldWrapper' object has no attribute 'month'
had resolved

But not able to change the date format still

I tryed to poke the source code of django

that have a file json.py
at line number 35 their is a class stated as
class DateTimeAwareJSONEncoder(simplejson.JSONEncoder):
"""
JSONEncoder subclass that knows how to encode date/time types
"""

DATE_FORMAT = "%Y-%m-%d"
TIME_FORMAT = "%H:%M:%S"

Does it makes any sense. sience I have already installed the django. I
don't guess that should work here.do i reinstall the django with the
DATE_FORMAT Change to "%d/%m%Y"

?????


Stuck Guys Help me


Although after reading this
http://groups.google.com/group/django-users/browse_thread/thread/f0e7d503401a7186/a20885d604dcad7a?lnk=gst&q=%7Cdate%3A%22Y+m+d%22&rnum=2#a20885d604dcad7a
I changed the date field to datetime field
The

On Mar 15, 12:58 am, "James Bennett" <ubernost...@gmail.com> wrote:

Malcolm Tredinnick

unread,
Mar 15, 2007, 2:27:32 AM3/15/07
to django...@googlegroups.com
On Thu, 2007-03-15 at 05:58 +0000, mralokkp wrote:
> Thanks James but the spaces had been removed
> If Spaces it gives template error.
> If not it gives the former error
> says
> AttributeError at /registration/
> 'FormFieldWrapper' object has no attribute 'month'
> had resolved

Reading the error message gives a clue as to what is going wrong here:
you are not formatting a datetime object, you are trying to call the
filter on a FormFieldWrapper object, which won't work. It sounds like
you are getting confused about the types of variables in your template
-- maybe you are accidently calling two things by the same name in your
view function or something like that.

Trim your problem down to a very small example. Make it a template that
only displays this one thing. Then make sure the error still occurs (if
not, introduce more things until it happens again). Then start removing
things from your view so that you are only passing the single variable
into the template, checking that the error occurs each time. At some
point, you will find the error goes away, so you will have more
information about what the critical line of code is.

Regards,
Malcolm

mralokkp

unread,
Mar 15, 2007, 2:51:58 AM3/15/07
to Django users
Kindly execute the code that i wish to do from django it self

# Simplyfied date format change that I wish to use in django
import datetime
t = datetime.date.today()
print t.strftime("%Y,%m,%d")
print "My Required Date Format is "
print t.strftime("%d,%m,%Y")

Can't i call this program to django to change the date format. if yes
then let me know.

Regards
Alok

On Mar 15, 11:27 am, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:


> On Thu, 2007-03-15 at 05:58 +0000, mralokkp wrote:
> > Thanks James but the spaces had been removed
> > If Spaces it gives template error.
> > If not it gives the former error
> > says
> > AttributeError at /registration/
> > 'FormFieldWrapper' object has no attribute 'month'
> > had resolved
>
> Reading the error message gives a clue as to what is going wrong here:

> you are not formatting a datetime object, you are trying to call thefilteron a FormFieldWrapper object, which won't work. It sounds like

Malcolm Tredinnick

unread,
Mar 15, 2007, 3:23:02 AM3/15/07
to django...@googlegroups.com
On Thu, 2007-03-15 at 06:51 +0000, mralokkp wrote:
> Kindly execute the code that i wish to do from django it self
>
>
>
> # Simplyfied date format change that I wish to use in django
> import datetime
> t = datetime.date.today()
> print t.strftime("%Y,%m,%d")
> print "My Required Date Format is "
> print t.strftime("%d,%m,%Y")
>
> Can't i call this program to django to change the date format. if yes
> then let me know.

Yes, you use the date filter in the template to do this. The error you
were seeing said you were not applying that filter to a date or datetime
variable, though. To work out why the variable does not contain what you
think, it might help to trim down your example as I suggested before.
That way you could post exactly what you are doing and it will only be a
few lines long.

Malcolm

mralokkp

unread,
Mar 15, 2007, 5:20:36 AM3/15/07
to Django users
Thanks Mr. M

Even Tryed this
http://magpiebrain.com/blog/2005/08/21/formatting-dates-with-django/
Covered Both Example
But Unable to get any clue.
Unable to find any proper documentation / Code example for this
I am new to Django. Advanced Thank
Regards

On Mar 15, 12:23 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:

Reply all
Reply to author
Forward
0 new messages