2

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.

1 Answer 1

3

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/

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.