Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#19211 closed Cleanup/optimization (fixed)

Tutorial must be updated for Python 3

Reported by: adj7388@… Owned by: nobody
Component: Documentation Version: master
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__()?":

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 4 years ago.
Adapt tutorial for Python 3

Download all attachments as: .zip

Change History (10)

comment:1 Changed 4 years ago by Aymeric Augustin

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
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 Changed 4 years ago by Luke Plant

Description: modified (diff)

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

comment:3 Changed 4 years ago by Tim Graham

Triage Stage: AcceptedSomeday/Maybe

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

comment:4 Changed 4 years ago by itsallvoodoo

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

comment:5 Changed 4 years ago by Claude Paroz

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.

Changed 4 years ago by Claude Paroz

Attachment: 19211.diff added

Adapt tutorial for Python 3

comment:6 Changed 4 years ago by Claude Paroz

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 Changed 4 years ago by Aymeric Augustin

Triage Stage: AcceptedReady for checkin

OK, let's do that.

comment:8 Changed 4 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In 7cc3acbb70c8f66060b377ed402df3085288b006:

Fixed #19211 -- Adapted tutorial for Python 3

comment:9 Changed 3 years ago by Claude Paroz <claude@…>

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