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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Jacob Kaplan-Moss
March 16, 2013
Technology
870
9
Share
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
1k
How to Ace a Technical Interview
jacobian
281
24k
Implementing Multi-factor Auth (dotSecurity 2016)
jacobian
10
1.6k
Heroku Under The Hood - Django Under The Hood 2015
jacobian
9
690
Django's request/response cycle - Django Under The Hood 2015
jacobian
9
1.5k
Minimum Viable Security - Wharton Web Conference 2015
jacobian
1
1.3k
Django minus Django (DJangoCon EU 2014)
jacobian
12
1.4k
Heroku 101 – PyCon 2014
jacobian
1
1k
Be Agile, Not Vulnerable: Security engineering in an agile world
jacobian
8
830
Other Decks in Technology
See All in Technology
TanStack Start エコシステムの現在地 / TanStack Start Ecosystem 2026
iktakahiro
1
350
組織的なAI活用を阻む 最大のハードルは コンテキストデザインだった
ixbox
1
1.2k
40代からのアウトプット ― 経験は価値ある学びに変わる / 20260404 Naoki Takahashi
shift_evolve
PRO
5
900
スクラムを支える内部品質の話
iij_pr
0
320
CC Workflow Studio
seiyakobayashi
0
100
AIを活用したアクセシビリティ改善フロー
degudegu2510
1
160
サイバーフィジカル社会とは何か / What Is a Cyber-Physical Society?
ks91
PRO
0
150
AIドリブン開発の実践知 ― AI-DLC Unicorn Gym実施から見えた可能性と課題
mixi_engineers
PRO
0
120
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
11k
Data Enabling Team立ち上げました
sansantech
PRO
0
290
Oracle Cloud Infrastructure(OCI):Onboarding Session(はじめてのOCI/Oracle Supportご利⽤ガイド)
oracle4engineer
PRO
2
17k
LLM とプロンプトエンジニアリング/チューターを定義する / LLMs and Prompt Engineering, and Defining Tutors
ks91
PRO
0
290
Featured
See All Featured
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
160
Are puppies a ranking factor?
jonoalderson
1
3.2k
Building Adaptive Systems
keathley
44
3k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2k
Paper Plane
katiecoart
PRO
1
49k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1k
The browser strikes back
jonoalderson
0
900
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.8k
The Limits of Empathy - UXLibs8
cassininazir
1
290
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
480
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!