Django May Not Be the Best Way to Learn Python

I learned to plan in Python indirectly. I was interested in researching web software development and observed good things about Django. I did not know Python, but the syntax and documentation seemed clear-cut enough Like every reasonable programmer, I found the language did not matter and I’d pick it up as I went.

Mainly, this was authentic. Python proved to be very learnable, and I was fast productive on my Django job. It wasn’t until long subsequent to the project was finished that I comprehended I hadn’t truly learned Python. I’d learned some unusual mutant hybrid language: part Python, part Django. Using Django to learn Python is a terrible approach to really learn Python. In this post, we will look at the official Django tutorial from a Pythonic viewpoint. From the conclusion, you will be convinced that programmers whose only exposure to Python is Django do not necessarily understand Python.

Settings is our first stop. The tutorial briefly mentions “It Is a normal Python module with module-level variants representing Django settings.”

To a beginner, is only a strangely formatted configuration file. The fact that it’s valid Python code, and that writing configuration files in pure Python can be quite a powerful instrument, is probably missed. Because is devoid of any “ordinary” Python statements aside from creating dictionaries and lists, it’s easy to miss the file itself is composed in Python. Personally, I did not pick up on this until I had been well in to my first project. I did not comprehend its worth until much after.

In regards to Django versions, the tutorial presents the following code:

from django.db import models

class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()

To start with, both classes inherit from django.db.models. Model. Why? There’s no explanation of why this is mandatory. Your “simple Python category” must inherit from our item, end-of story.

Then there is the industry declarations. Have you ever written a non-ORM based category in Python that appeared anything just like the example? No __init__ perform, no reference to self. Heck, there aren’t any instance attributes declared. Only a listing of type credits assigned to some group of cryptic Django area objects. In short, this group seems unlike any Python category you’ll ever write outside of Django. (Unless it is an abstract base class)

There Is a more important issue with all the tutorial’s treatment of models. For the benefit of making Django’s ORM approachable, all ‘info’ in Django programs are encapsulated with a Group. It’s an unintentional message to new Python programmers: Python is object-oriented everywhere; you should be also.

Naturally, most experienced Python programmers use objects only when crucial. They prefer Python’s built in data structures, specially when making APIs. Using indigenous Python data structures is the closest thing to a free lunch which exists with regard to application maintainability. I can not think of a single bundle I use regularly that encapsulates everything in a number of categories and powers the end-user to do the exact same.

URL Routines
They’re basically merely a lot of insane configuration settings as far as the consumer is concerned. What urlpatterns really is (a list of lists, tuples, and RegexURLPatterns, which are then further changed for resolution) is outstanding in its unclarity (a new term). I’m bypassing this segment from wrath.

Here’s the brief snippet of code regarding views provided in the tutorial:

urlpatterns = patterns('',
url(r'^polls/$', 'polls.views.index'),
url(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),
url(r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'),
url(r'^polls/(?P<poll_id>\d+)/vote/$', ''),
url(r'^admin/', include(,

The fact that it uses the function names as strings makes my blood boil. For rookie Python programmers, understanding that everything really is an object is revelatory. When they finally comprehend that stuff like functions, groups (not only examples!), modules, and code things may be passed as arguments, it is an incredible second. They eventually start to glimpse the purpose and power of “every thing is an object.”

The fact that the string even contains the relative import path is face-slappery.

In all nine of the examples, it’s neither employed nor mentioned once. A superb lesson in style for novices…

Wrapping Up
I’m ceasing prior to the end of the tutorial since I’m unfairly bashing Django. It’s a fantastic project in every way I can think of, and also the owners manual is a good example of instruction manual done right. It Is vulnerable to my criticisms as it isn’t designed to coach you on how to program in Python. Regardless, for many Django symbolizes their first introduction to the language. If you are looking for a excellent internet framework in Python, look to Django. If you’re appearing to understand Python, look someplace else.

8 thoughts on “Django May Not Be the Best Way to Learn Python

  1. Great post, thanks. I’m doing this for canada and adding the provinces. They show up in the admin and I’m adding the flat rate shipping but when I calculate the shipping rates from the front end they do not come up. I was wondering if I have the country codes right example ca-bc. Where did you find the codes that wp-ecomcerce is using for its variables? Could this be something else?

  2. FieldogLe problème n’est pas de savoir si finalement il y a ou pas plusieurs styles de joueurs mais de voir le style qui aujourd’hui permet de gagner les tournois.Disons depuis 2008 fin de la période de grâce de FED nous avonsNadal: 7 GCDjoko : 5 GCSoit 12 GC sur 17 possible. Enlevons les 4 de FED reste 12 sur 13.Le débat me semble clos avant d’avoir commencé faute d’autres adversaires à ce style de jeu basé sur le physique et renvoyer la balle une fois de plus que l’autre.

  3. Quero EMBARCAR na emoção, NAVEGAR na diversão com ONDAS de Bem-Estar e satisfação e depois ANCORAR a melhor sensação de me exercitar com “Kangoo Jumps” , dentro de um CRUZEIRO que é pura inspiração!

Leave a Reply

Your email address will not be published. Required fields are marked *