Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#19211 closed Cleanup/optimization (fixed)

Tutorial must be updated for Python 3

Reported by: adj7388@… 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 Luke Plant)

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)

19211.diff (2.2 KB ) - added by Claude Paroz 12 years ago.
Adapt tutorial for Python 3

Download all attachments as: .zip

Change History (10)

comment:1 by Aymeric Augustin, 12 years ago

Summary: 1.5 Tutorial wrong about __unicode__() method for Python 3Tutorial must be updated for Python 3
Triage Stage: UnreviewedAccepted

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.

comment:2 by Luke Plant, 12 years ago

Description: modified (diff)

Description fixed - you can include literal code by enclosing in backticks, as described on WikiFormatting.

comment:3 by Tim Graham, 12 years ago

Triage Stage: AcceptedSomeday/Maybe

Moving this to "Someday" since it's not immediately actionable.

comment:4 by itsallvoodoo, 12 years ago

I have submitted a pull request, #874, that addresses this issue.

comment:5 by Claude Paroz, 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.

by Claude Paroz, 12 years ago

Attachment: 19211.diff added

Adapt tutorial for Python 3

comment:6 by Claude Paroz, 12 years ago

Has patch: set
Triage Stage: Someday/MaybeAccepted
Version: 1.5-alpha-1master

I followed the tutorial, and think the attached patch solves the compatibility issues.

comment:7 by Aymeric Augustin, 12 years ago

Triage Stage: AcceptedReady for checkin

OK, let's do that.

comment:8 by Claude Paroz <claude@…>, 12 years ago

Resolution: fixed
Status: newclosed

In 7cc3acbb70c8f66060b377ed402df3085288b006:

Fixed #19211 -- Adapted tutorial for Python 3

comment:9 by Claude Paroz <claude@…>, 11 years ago

In 406fd9f97f4b04212276e2e78d8216ef5a27a514:

Fixed #19211 -- Adapted tutorial for Python 3

Backport of 7cc3acbb7 from master.

Note: See TracTickets for help on using tickets.
Back to Top