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
770
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
850
How to Ace a Technical Interview
jacobian
272
22k
Implementing Multi-factor Auth (dotSecurity 2016)
jacobian
10
1.3k
Heroku Under The Hood - Django Under The Hood 2015
jacobian
9
500
Django's request/response cycle - Django Under The Hood 2015
jacobian
9
1.1k
Minimum Viable Security - Wharton Web Conference 2015
jacobian
1
910
Django minus Django (DJangoCon EU 2014)
jacobian
12
1.3k
Heroku 101 – PyCon 2014
jacobian
1
870
Be Agile, Not Vulnerable: Security engineering in an agile world
jacobian
8
650
Other Decks in Technology
See All in Technology
最近たまに見かけるTiDBってなんだ? - Findy
pingcap0315
2
740
よく聞くけど使ったことないソフトウェアNo.1 KafkaとSnowflake
foursue
4
320
〜小さく始めて大きく育てる〜データ分析基盤の開発から活用まで
kniino
0
2.1k
「スニダン」開発組織の構造に込めた意図 ~組織作りはパッションや政治ではない!~
rinchsan
3
470
継続的な改善 x ⾮連続的な進化
sansantech
PRO
3
130
EMとして2023年度に頑張ったこと / What we did well in FY2023 as a EM
pauli
1
150
2024/4/26 コンピュータ歴史博物館解説告知
toshi_atsumi
0
210
カオナビの利用実績をアウトカムへつなげる旅 / example-of-data-management-startup-in-kaonavi
kaonavi
0
130
NgRx Signal Store
rainerhahnekamp
0
140
Google Cloud Next '24でブログを10本書いた方法と勉強会を沸かせた方法
yasumuusan
0
250
JSON攻略法.pdf
miyakemito
8
4.5k
プロデザ! BY リクルート vol.18_リクルートのリサーチ実践組織「リサーチブーストコミュニティ」
recruitengineers
PRO
3
260
Featured
See All Featured
BBQ
matthewcrist
80
8.8k
The Invisible Side of Design
smashingmag
294
49k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
243
20k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
24
2.3k
Building a Modern Day E-commerce SEO Strategy
aleyda
16
6.4k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
5
1.5k
Rails Girls Zürich Keynote
gr2m
91
13k
Design by the Numbers
sachag
274
18k
Become a Pro
speakerdeck
PRO
10
4.5k
Art, The Web, and Tiny UX
lynnandtonic
288
19k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
1
1.3k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
220
21k
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!