Code

Opened 18 months ago

Closed 12 months ago

Last modified 7 months 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 lukeplant)

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 claudep 12 months ago.
Adapt tutorial for Python 3

Download all attachments as: .zip

Change History (10)

comment:1 Changed 18 months ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from 1.5 Tutorial wrong about __unicode__() method for Python 3 to Tutorial must be updated for Python 3
  • Triage Stage changed from Unreviewed to Accepted

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 18 months ago by lukeplant

  • Description modified (diff)

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

comment:3 Changed 18 months ago by timo

  • Triage Stage changed from Accepted to Someday/Maybe

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

comment:4 Changed 14 months ago by itsallvoodoo

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

comment:5 Changed 14 months ago by claudep

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 12 months ago by claudep

Adapt tutorial for Python 3

comment:6 Changed 12 months ago by claudep

  • Has patch set
  • Triage Stage changed from Someday/Maybe to Accepted
  • Version changed from 1.5-alpha-1 to master

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

comment:7 Changed 12 months ago by aaugustin

  • Triage Stage changed from Accepted to Ready for checkin

OK, let's do that.

comment:8 Changed 12 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 7cc3acbb70c8f66060b377ed402df3085288b006:

Fixed #19211 -- Adapted tutorial for Python 3

comment:9 Changed 7 months ago by Claude Paroz <claude@…>

In 406fd9f97f4b04212276e2e78d8216ef5a27a514:

Fixed #19211 -- Adapted tutorial for Python 3

Backport of 7cc3acbb7 from master.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.