Django book

Just finished to download the online version of Django book, the most famous book on this great Python web framework. Django makes some common tasks trivial. For example, here's how this framework handles browser detection:

def ua_display_good1(request):
        ua = request.META['HTTP_USER_AGENT']
    except KeyError:
        ua = 'unknown'
    return HttpResponse("Your browser is %s" % ua)

def ua_display_good2(request):
    ua = request.META.get('HTTP_USER_AGENT', 'unknown')
    return HttpResponse("Your browser is %s" % ua)

Since Python is an object-oriented language, you can use this feature to access methods and properties, while in other languages you have to deal with superglobal arrays (just as PHP does). Using objects, on the other hand, is a more secure approach. For example, to sanitize user input, you need only one line of code in Python and Django! That's why I love Python and Django.

Leave a Reply

Note: Only a member of this blog may post a comment.