DateTimeField received a naive datetime (2013-01-10 00:00:00) while time zone support is active.

105 views
Skip to first unread message

Jeff Hsu

unread,
Jan 11, 2013, 3:23:17 AM1/11/13
to django...@googlegroups.com
Hi all,

       I kept getting DateTimeField received a naive datetime (2013-01-10 00:00:00) while time zone support is active. but I can't figure out where it's receiving a naive datetime.  I have USE_TZ set to True in my setting file(stores timezone aware object in mysql?).  My url is as below:

urlpatterns = patterns('django.views.generic.date_based', #add the repetitive pattern here
    url(r'^$', 'archive_index', entry_info_dict, name='coltrane_entry_archive_index'),
    url(r'^(?P<year>\d{4})/$','archive_year', entry_info_dict, name='coltrane_entry_archive_year'),
    url(r'^(?P<year>\d{4})/(?P<month>\w{3})/$','archive_month', entry_info_dict, 
        name='coltrane_entry_archive_month'),
    url(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/$','archive_day', entry_info_dict, 
        name='coltrane_entry_archive_day'),
    url(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$',
        'object_detail', entry_info_dict, name='coltrane_entry_detail'), #the forth arg will this patter a name
         #[-\w] will match letter, number or a hyphen
)

Every time I access a detail page from the archive index page, the error will pop out.  I'm using generic view to do my detail page, and I can figure out what's wrong.  Can anybody give me some direction?

http://dpaste.com/871999/

Thank you,
Jeff

Tom Evans

unread,
Jan 11, 2013, 5:13:23 AM1/11/13
to django...@googlegroups.com
Function based generic views were deprecated in 1.3, TZ support
appeared in 1.4.

When a date based generic view is asked to filter against a
DateTimeField, it takes the specified day, and filters that field is
between datetime.combine(date, time.min) and datetime.combine(date,
time.max). datetime.combine only returns TZ aware datetimes if the
time supplied is TZ aware (time.min/time.max are not).

I suggest you update to use the class based generic views that arrived in 1.3:

https://docs.djangoproject.com/en/1.4/topics/generic-views-migration/

Cheers

Tom

Iñigo Medina

unread,
Jan 11, 2013, 3:58:22 AM1/11/13
to django...@googlegroups.com
On Fri, Jan 11, 2013 at 12:23:17AM -0800, Jeff Hsu wrote:
> Hi all,
>
> I kept getting DateTimeField received a naive datetime (2013-01-10
> 00:00:00) while time zone support is active. but I can't figure out where
> it's receiving a naive datetime. I have USE_TZ set to True in my setting
> file(stores timezone aware object in mysql?). My url is as below:

You get some good tips for configuration and tracebak on this post:
http://note.harajuku-tech.org/datetimefield-received-a-naive-datetime-while

I�igo


>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/q3z2y6RI3x4J.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
Reply all
Reply to author
Forward
0 new messages