Django Error: NameError name 'current_datetime' is not defined

Posted by Diego on Stack Overflow See other posts from Stack Overflow or by Diego
Published on 2010-05-21T02:07:37Z Indexed on 2010/05/21 2:10 UTC
Read the original article Hit count: 692

I'm working through the book "The Definitive Guide to Django" and am stuck on a piece of code.

This is the code in my settings.py:

ROOT_URLCONF = 'mysite.urls'

I have the following code in my urls.py

from django.conf.urls.defaults import *
from mysite.views import hello, my_homepage_view

urlpatterns = patterns('', ('^hello/$', hello),
)

urlpatterns = patterns('', ('^time/$', current_datetime),
)

And the following is the code in my views.py file:

from django.http import HttpResponse
import datetime

def hello(request):
    return HttpResponse("Hello World")

def current_datetime(request):
    now = datetime.datetime.now()
    html = "<html><body>It is now %s.</body></html>" % now
    return HttpResponse(html)

Yet, I get the following error when I test the code in the development server.

NameError at /time/

name 'current_datetime' is not defined

Can someone help me out here? This really is just a copy-paste from the book. I don't see any mistyping.

© Stack Overflow or respective owner

Related posts about python

Related posts about django