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
880
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
281
24k
Implementing Multi-factor Auth (dotSecurity 2016)
jacobian
10
1.6k
Heroku Under The Hood - Django Under The Hood 2015
jacobian
9
730
Django's request/response cycle - Django Under The Hood 2015
jacobian
9
1.6k
Minimum Viable Security - Wharton Web Conference 2015
jacobian
1
1.3k
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
860
Other Decks in Technology
See All in Technology
取引先から届く 「セキュリティチェックシート」の読み解き方
kamadamakoto
0
150
グローバル基準のSREは、運用現場でどう機能したか:成熟度アセスメントの実践 / SRE NEXT 2026
sorawatanabe
0
210
つくって納得、つかって実感! 大規模言語モデルことはじめ ver2.0
recruitengineers
PRO
4
1.6k
[しろおび夏祭り2026] チャットするAIから、作業するAIへ - 使われ方の変化と、その裏側で起きていること
kk0n
0
1.7k
ガバメント AI 源内を地方自治体は活用できるのか可能性と課題、期待について
takeda_h
1
400
20260804_Q4AzureUpdateBite_FabricDataAgentの精度を高める設計.pdf
matayuuu
1
130
JavaScript 研修 (2026)
recruitengineers
PRO
2
530
攻撃と防御で学ぶAI時代のプロダクトセキュリティ演習
recruitengineers
PRO
9
2.7k
FPGAが実現する遠方宇宙の高空間分解能天体撮影 -大型地上望遠鏡の視力を補正する「補償光学」とは?-
komei_mt
0
230
まちスペース®とデジタルツインと「まちづくり」
hiro_ogi
0
100
Invisible to AI? Making TYPO3 Sites Quotable by AI Search Systems
wolfgangwagner
0
200
認知負荷をGemini で溶かす — GKE 基盤「Orbit」における AI エージェントの実践
sansantech
PRO
1
290
Featured
See All Featured
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
460
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Bash Introduction
62gerente
615
220k
Designing for humans not robots
tammielis
254
26k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
GraphQLとの向き合い方2022年版
quramy
50
15k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.5k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
220
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
We Are The Robots
honzajavorek
0
300
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
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!