Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Porting Django apps to Python 3
Search
Jacob Kaplan-Moss
March 16, 2013
Technology
890
9
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Porting Django apps to Python 3
PyCon 2013.
Jacob Kaplan-Moss
March 16, 2013
More Decks by Jacob Kaplan-Moss
See All by Jacob Kaplan-Moss
To ••• With Passwords
jacobian
4
1.1k
How to Ace a Technical Interview
jacobian
280
24k
Implementing Multi-factor Auth (dotSecurity 2016)
jacobian
10
1.7k
Heroku Under The Hood - Django Under The Hood 2015
jacobian
9
750
Django's request/response cycle - Django Under The Hood 2015
jacobian
9
1.6k
Minimum Viable Security - Wharton Web Conference 2015
jacobian
1
1.4k
Django minus Django (DJangoCon EU 2014)
jacobian
12
1.5k
Heroku 101 – PyCon 2014
jacobian
1
1k
Be Agile, Not Vulnerable: Security engineering in an agile world
jacobian
8
880
Other Decks in Technology
See All in Technology
複雑な業務システムを高速でつくるため、チーム全員をつくれる人へ
ayakurabuchi
0
120
AIがGISを代替する日:〜すべてをAIが創る時代に、私たちがFOSS4Gに関わる意味〜
lehupa
0
200
Copilot Coworkで「みのるん式」やってみた
minorun365
PRO
2
1.4k
Don't write the architecture only in the prompt.
neohsu
0
310
スマートロックを支えるFlutter × ネイティブ連携の実践 / Flutter and Native Integration in Practice: Powering Smart Locks
bitkey
PRO
0
150
仕様駆動開発の、その先へ。決める力と確かめる仕組み
inariku
1
170
バックオフィスに染み出すTypeScript ── clasp で安全に仕組みを作る
nealle
1
170
Jev の中身は50行で再現できる。でも本物との差はどこにあるのか
hisuzuya
0
290
素人でもできた!AIを使った短編小説創作入門
delhi09
PRO
0
300
なぜ東京にいる私が、新潟の技術コミュニティを運営するのか by 八雲慎之助
yakumo
0
220
視野はAIに、視座は人に / ai-for-breadth-humans-for-perspective
nkzn
6
2.8k
WireGuard for Apache NuttX - Bringing Secure Remote Access to embedded Devices -
aki310ooooo
0
140
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Thoughts on Productivity
jonyablonski
76
5.4k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
HDC tutorial
michielstock
2
990
Practical Orchestrator
shlominoach
192
12k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
440
Statistics for Hackers
jakevdp
799
230k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
510
Rails Girls Zürich Keynote
gr2m
96
14k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.4k
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!