views:

203

answers:

1

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.

+2  A: 

Change:

from mysite.views import hello, my_homepage_view

To this:

from mysite.views import current_datetime, hello, my_homepage_view

Here's some documentation: http://www.djangobook.com/en/1.0/chapter03/

Adam Bernier
Wow, that makes me feel like a dummy... thanks for the answer!!.. right under my nose
Diego