Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Porting Django apps to Python 3
Search
Jacob Kaplan-Moss
March 16, 2013
Technology
9
830
Porting Django apps to Python 3
PyCon 2013.
Jacob Kaplan-Moss
March 16, 2013
Tweet
Share
More Decks by Jacob Kaplan-Moss
See All by Jacob Kaplan-Moss
To ••• With Passwords
jacobian
4
990
How to Ace a Technical Interview
jacobian
278
23k
Implementing Multi-factor Auth (dotSecurity 2016)
jacobian
10
1.5k
Heroku Under The Hood - Django Under The Hood 2015
jacobian
9
610
Django's request/response cycle - Django Under The Hood 2015
jacobian
9
1.4k
Minimum Viable Security - Wharton Web Conference 2015
jacobian
1
1.2k
Django minus Django (DJangoCon EU 2014)
jacobian
12
1.4k
Heroku 101 – PyCon 2014
jacobian
1
970
Be Agile, Not Vulnerable: Security engineering in an agile world
jacobian
8
780
Other Decks in Technology
See All in Technology
dipにおけるSRE変革の軌跡
dip_tech
PRO
1
210
LLM開発を支えるエヌビディアの生成AIエコシステム
acceleratedmu3n
0
370
robocopy の怖い話/scary-story-about-robocopy
emiki
0
450
Gemini in Android Studio - Google I/O Bangkok '25
akexorcist
0
180
データ基盤の管理者からGoogle Cloud全体の管理者になっていた話
zozotech
PRO
0
290
JAWS AI/ML #30 AI コーディング IDE "Kiro" を触ってみよう
inariku
3
210
20250728 MCP, A2A and Multi-Agents in the future
yoshidashingo
1
210
VLMサービスを用いた請求書データ化検証 / SaaSxML_Session_1
sansan_randd
0
210
2025新卒研修・HTML/CSS #弁護士ドットコム
bengo4com
3
13k
【CEDEC2025】現場を理解して実現!ゲーム開発を効率化するWebサービスの開発と、利用促進のための継続的な改善
cygames
PRO
0
700
SAE J1939シミュレーション環境構築
daikiokazaki
1
220
マルチモーダル基盤モデルに基づく動画と音の解析技術
lycorptech_jp
PRO
4
470
Featured
See All Featured
A designer walks into a library…
pauljervisheath
207
24k
Raft: Consensus for Rubyists
vanstee
140
7k
Thoughts on Productivity
jonyablonski
69
4.8k
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.5k
Why Our Code Smells
bkeepers
PRO
337
57k
What's in a price? How to price your products and services
michaelherold
246
12k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
GitHub's CSS Performance
jonrohan
1031
460k
A Modern Web Designer's Workflow
chriscoyier
695
190k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
18
1k
Visualization
eitanlees
146
16k
Transcript
Porting Django apps to Python 3 Jacob Kaplan-Moss
[email protected]
“Django 1.5 is… the first release with Python 3 support!
... Everything’s in place for you to start porting your apps to Python 3.” — https://docs.djangoproject.com/en/1.5/releases/1.5/
Do I want to use Python 3?
ˑYes!
Python 3: now with 30% fewer warts!
ˑ Unicode no longer sucks!
Can I use Python 3?
✓ SQLite ✓ PostgreSQL ✘ MySQL
✓ modwsgi ✓ uWSGI ✓ gunicorn: sync ✘ gunicorn: async
✓ South ✓ Celery ✓ django-pipeline ✘ django-debug-toolbar ✘ django-registration
✘ django-extensions ✘ Haystack ✘ django-tagging ✘ Sentry ✘ django-compressor
Should I use Python 3?
Options 1. Python 3 only. 2. Translated source (2to3). 3.
Single codebase.
Python 3 only?
2to3
ˑ Single source wins!
HOWTO
1. Choose an approach
2. Evaluate dependencies
3. Get the test suite running
4. Fix unicode handling
5. Iterate on test failures
Case study: a new website
1. Choose an approach Single source: Python 3.3 only.
2. Evaluate dependencies • Light CMS capabilities. • Moderately complex
user / permissions / authentication system. • Heavy integration with social networks. • Moderate traffic with extreme “spikes.”
3. Get the test suite running ✓ django-discover-runner
4. Fix unicode handling django.utils.encoding
ˑIt works! ... but costs ~20% more.
Case study: django-sitetree Ported by Jeff Triplett (@webology) https://github.com/idlesign/django-sitetree/commit/c7475
1. Choose an approach Shared source: Python 2.6+, 3.3; Django
1.4+
2. Evaluate dependencies None (whew).
3. Get the test suite running Tox: http://tox.readthedocs.org/
Tox [tox] envlist -‐ py27-‐django14, py33-‐django15 [py27-‐django14] basepython = python2.7
deps = Django==1.4 [py33-‐django15] basepython = python33 deps = Django==1.5
Syntax changes print "foo" print("foo") except Exception, ex:
except Exception as ex: raise Exception, "msg" raise Exception("message”) class C: class C(metaclass=M) __metaclass__ = M More: http://docs.python.org/3.0/whatsnew/3.0.html 2 3
4. Fix unicode handling django.utils.encoding
Models and unicode class M(models.Model): class M(models.Model):
def __unicode__(self): def __str__(self): return self.name return self.name @python_2_unicode_compat class M(models.Model): def __str__(self): return self.name 2 3
5. Iterate on test failures Six: http://pythonhosted.org/six/ (also django.utils.six)
Six class C:
class C(metaclass=M) __metaclass__ = M class C(six.with_metaclass(M)): 2 3
Six isinstance(s, str) isinstance(s, bytes) isinstance(s, unicode) isinstance(s,
str) isinstance(s, six.binary_type) isinstance(s, six.text_type) 2 3
Six if six.PY3: ...
ˑ django.me/py3 is your new bicycle
Thanks! Jacob Kaplan-Moss
[email protected]
Questions? Follow me to room 201!