#14052 closed (invalid)
Error on a code in Tutorial 01
| Reported by: | Wagner Macedo | Owned by: | nobody |
|---|---|---|---|
| Component: | Documentation | Version: | 1.2 |
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I'm learning Python and Django, and in tutorial 01, on url http://docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01, I think the code that's adding a custom method in the Poll class is wrong. Where is written:
import datetime
# ...
class Poll(models.Model):
# ...
def was_published_today(self):
return self.pub_date.date() == datetime.date.today()
should be:
import datetime # ... class Poll(models.Model): # ... def was_published_today(self): return self.pub_date.date() == datetime.today().date()
The error is in the order today date invocation.
Sorry for my poor english, I'm brazillian.
Change History (2)
comment:1 by , 15 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
comment:2 by , 15 years ago
Sorry for annoy by this ticket. The tutorial code is right, but with me didn't work because I was using Eclipse to edit the code and the autocompletion of datetime added incorrectly the import
from django.utils.datetime_safe import datetime
that uses datetime instance
The tutorial code is correct. Try it in a Python shell:
The proposed change does not work:
Using the
today()constructor of thedatetime.datetimeclass instead of trying it on thedatetimemodule (yes, this is a bit confusing in Python) would work:But the existing code is simpler and works, so is preferable.