1

Recently I was working on my Django web app, when I discovered that for some reason Django only worked when I used a python 2.x. Interpreter, but all the while I had thought it had been configured for Python 3 and thus was coding like so.

So I tested it with print(sys.version()) and was surprised when Python 2.7 came out. After a little digging I discovered that Django uses the six module. My first question is why does Django use this? Is there any reason other than just making it easier on the programmer? My second question is, since I've been treating it like Python 3 should I go back and change my code so that it is pure Python 2? Or does it not matter?

P.s. I kinda understand how six works, but it would be great to know a little more about it.

Thanks.

Anthony
  • 670
  • 6
  • 20

2 Answers2

2

Django 1.5 is the first version of Django to support Python 3. The same code runs both on Python 2 (≥ 2.6.5) and Python 3 (≥ 3.2), thanks to the six compatibility layer.

Writing compatible code is much easier if you target Python ≥ 2.6. Django 1.5 introduces compatibility tools such as django.utils.six, which is a customized version of the six module. For convenience, forwards-compatible aliases were introduced in Django 1.4.2. If your application takes advantage of these tools, it will require Django ≥ 1.4.2.

For More read through Porting to Python 3

coder3521
  • 2,608
  • 1
  • 28
  • 50
0

Which Python version your system uses has nothing whatsoever to do with the six module. That's something that Django uses internally to be able to work with both 2.7 and 3.x.

If you want to use Python 3 locally, you need to configure your system to do so. That might just mean creating your virtualenv with Python 3, for example.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895