This must be very simple, but I'm stumped.
Here's the code for views.py
from django.http import HttpResponse
import datetime
def current_datetime(request):
now = datetime.datetime.now()
html = "<html><body>It is now %s.</body></html>" % now
return HttpResponse(html)
The offending line is:
now = datetime.datetime.now()
The code's cut and pasted from the Django 1.1 tutorial (http://
docs.djangoproject.com/en/1.1/topics/http/views/), and I have Django
1.1.1.
datetime.datetime.now() works as a function call at the Python shell:
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2010, 2, 10, 5, 17, 21, 218000)
Any ideas? Thanks,
Nick
Before:
> html = "<html><body>It is now %s.</body></html>" % now
After:
> html = "<html><body>It is now %s.</body></html>" % (now,)
Shawn
I renamed the "now" variable as "dt" but it didn't help. I've also
tried your 1-tuple idea-- no change.
Note that the offending line isn't the html assignment but:
now = datetime.datetime.now()
Make sure your import line is correct.
In [1]: import datetime
In [2]: datetime.datetime.now()
Out[2]: datetime.datetime(2010, 2, 9, 14, 23, 25, 155503)
--
Decemba, n: The 12th month of the year.
erra, n: A mistake.
faa, n: To, from, or at considerable distance.
Linder, n: A female name.
memba, n: To recall to the mind; think of again.
New Hampsha, n: A state in the northeast United States.
New Yaak, n: Another state in the northeast United States.
Novemba, n: The 11th month of the year.
Octoba, n: The 10th month of the year.
ova, n: Location above or across a specified position. What the
season is when the Knicks quit playing.
-- Massachewsetts Unabridged Dictionary
> On Tuesday 09 February 2010 14:19:17 Nick Mellor wrote:
>> Thanks Shaun,
>>
>> I renamed the "now" variable as "dt" but it didn't help. I've also
>> tried your 1-tuple idea-- no change.
>>
>> Note that the offending line isn't the html assignment but:
>>
>> now = datetime.datetime.now()
>>
>
> Make sure your import line is correct.
>
> In [1]: import datetime
>
> In [2]: datetime.datetime.now()
> Out[2]: datetime.datetime(2010, 2, 9, 14, 23, 25, 155503)
>
> -
To clarify this, if you are doing:
from datetime import datetime
then you'd need to use datetime.now() instead of datetime.datetime.now().
Shawn
Thanks Shaun,
I renamed the "now" variable as "dt" but it didn't help. I've also
tried your 1-tuple idea-- no change.
Note that the offending line isn't the html assignment but:
now = datetime.datetime.now()
Be very sure that the spelling of everything in the file in question is correct
and that you aren't, for example, using the name "datetime" for something
else between the import and the usage.
If you're running in the development server, it is easy to stick in
pdb.set_trace()
(you'll have to import pdb) just before the offending line, and poke around when
you hit the breakpoint to see what datetime really is at that point.
If you don't hit the breakpoint, then you're not running with the file
you're editing.
Be sure that your really said "import datetime" rather than
"from datetime import datetime" (which is the way that I typically
import it) or that
someone else hasn't done that after your import.
If you're not running in the development server, then you might replace your
"now = ..." and "html = ..." lines with:
html = "<html><body>datetime is %r.</body></html>" % datetime
which will tell you what datetime is at that point. You will have to
restart apache
(or perhaps touch your .wsgi script file).
Bill
On Tue, Feb 9, 2010 at 5:19 PM, Nick Mellor
<nick.mell...@pobox.com> wrote:
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> 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.
>
>