Re: name 'current_datetime' is not defined

2007-02-03 Thread Mike Spradling

I figured it out, I left off

from mysite.views import current_datetime


On Feb 3, 8:50 am, "gordyt" <[EMAIL PROTECTED]> wrote:
> Howdy Mike,
>
> > def current_datetime(request):
> > now = datetime.datetime.now()
> > html = "It is now %s." % now
> > return HttpResponse(html)
>
> > - then edit your urls.py to contain
>
> > from django.conf.urls.defaults import *
>
> > urlpatterns = patterns('',
> > (r'^now/$', current_datetime),
>
> You just need to let Django know about the module that contains the
> current_datetime function.
>
> For example, if your project name is "myproject" and your app name is
> "myapp", you would do this:
>
> urlpatterns = patterns('myproject.myapp.views',
> (r'^now/$', current_datetime),
> )
>
> --gordy


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



name 'current_datetime' is not defined

2007-02-03 Thread Mike Spradling

I'm baffled.  I'm just getting started with django and am reading the
'Django Book'.  In chapter 3 I'm told,

- Make a file called views.py that contains:

from django.http import HttpResponse
import datetime

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

- then edit your urls.py to contain

from django.conf.urls.defaults import *

urlpatterns = patterns('',
(r'^now/$', current_datetime),
)

then start the server and go to http://myserver:8080/now/

I immediately get

Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py"
in get_response
  68. callback, callback_args, callback_kwargs =
resolver.resolve(request.path)
File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py" in
resolve
  160. for pattern in self.urlconf_module.urlpatterns:
File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py" in
_get_urlconf_module
  177. self._urlconf_module = __import__(self.urlconf_name, {}, {},
[''])

  NameError at /now/
  name 'current_datetime' is not defined

What am I missing?  I tried both the stable build, and the latest svn
with the same results


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---