Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Porting Django apps to Python 3

Porting Django apps to Python 3

Presented at DjangoCon AU 2013.

Jacob Kaplan-Moss

July 04, 2013
Tweet

More Decks by Jacob Kaplan-Moss

Other Decks in Technology

Transcript

  1. “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.” — http://django.me/1.5 “As of Django 1.6, Python 3 support is considered stable and you can safely use it in production. — http://django.me/faq
  2. ✓ South ✓ Celery ✓ Raven (Sentry) ✓ django-extensions ✘

    django-compressor ✘ django-social-auth ✘ django-tagging ✘ django-debug-toolbar ✘ django-registration ✘ Haystack
  3. ✓ South ✓ Celery ✓ Raven (Sentry) ✓ django-extensions ✓

    django-pipeline ✓ django-allauth ✓ django-taggit ✘ django-debug-toolbar ✘ django-registration ✘ Haystack
  4. 2. Evaluate dependencies • Light CMS capabilities. • Moderately complex

    user / permissions / authentication system. • Heavy integration with social networks. • Moderate traffic with extreme “spikes.”
  5. Tox [tox] envlist  -­‐  py27-­‐django14,  py33-­‐django15 [py27-­‐django14] basepython  =  python2.7

    deps  =  Django==1.4 [py33-­‐django15] basepython  =  python33 deps  =  Django==1.5
  6. 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
  7. 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
  8. Six class  C:              

                         class  C(metaclass=M)      __metaclass__  =  M class  C(six.with_metaclass(M)): 2 3
  9. 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