#19211 closed Cleanup/optimization (fixed)
Tutorial must be updated for Python 3
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | python3 unicode str |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
When using Python 3.3 and 1.5-alpha-1.
See this section of the tutorial "Why __unicode__()
and not __str__()
?": https://docs.djangoproject.com/en/1.5/intro/tutorial01/#playing-with-the-api
This section of the tutorial says to add __unicode__()
method to your Model classes so that admin and shell display useful strings. This is correct for Python 2.x, but breaks object display under Python 3.3. __str__()
should be used instead of __unicode__()
. Tutorial probably needs a sidebar or other additional information for users using Python 3.x.
Attachments (1)
Change History (10)
comment:1 by , 12 years ago
Summary: | 1.5 Tutorial wrong about __unicode__() method for Python 3 → Tutorial must be updated for Python 3 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 12 years ago
Description: | modified (diff) |
---|
Description fixed - you can include literal code by enclosing in backticks, as described on WikiFormatting.
comment:3 by , 12 years ago
Triage Stage: | Accepted → Someday/Maybe |
---|
Moving this to "Someday" since it's not immediately actionable.
comment:5 by , 12 years ago
I wonder if just mentioning that on Python 3, you have to replace __unicode__
by __str__
would be enough to make the tutorial Python 3-friendly. If someone could follow the whole tutorial on Python 3 with this idea in mind and report the outcome, it would be helpful.
Now that we advertised support for Python 3 in Django 1.5, even if we called it "experimental", I think we will have more and more users following the tutorial on Python 3.
comment:6 by , 12 years ago
Has patch: | set |
---|---|
Triage Stage: | Someday/Maybe → Accepted |
Version: | 1.5-alpha-1 → master |
I followed the tutorial, and think the attached patch solves the compatibility issues.
comment:8 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
At the moment Python 3 support is labeled "experimental"; it's targeted at people who know what they're doing.
It seems difficult to introduce the differences between Python 2 and Python 3 in a beginner-friendly manner.
I prefer to keep a 2.x-only tutorial for now, and switch to a 3.x-only tutorial in Django 1.7 (give or take one version). It depends on how fast the Django ecosystem supports Python 3.