1. Real-time Applications and will Django adapt to it?

    While talking about Django at PyCon India this year, the most common question I got was whether it supports Single Page applications or an event driven architecture. I was quick to point out that such realtime applications are usually a handled by separate services at the backend (running on a different port?) and a JavaScript MVC framework on the front. Sometimes, Django supported by a REST library like Django REST or Piston is used as the backend too.

    But the more I thought about it, those questions felt more and more important. Then, I had a chance to read about Meteor. I tried some of their tutorials and they were fantastic. I was so impressed at that point that I felt this framework had the power to change web development in a big way. I was even tempted to write an article similar to Why Meteor will kill Ruby on Rails for Django. But then, better sense prevailed and I dug deeper.

    So I wrote this post to really understand the Real-time web application phenomena and pen my thoughts around it. It will look at how a traditional web framework like Django might tackle it or whether it really can ...

    Continue Reading →
  2. Building a Hacker News clone in Django - Part 4 (AJAX and Mixin)

    You are reading a post from a four-part tutorial series

    Yes, all good things do come to an end. It gets even better when the ending is good. Steel Rumors was a project to help Django beginners progress to the next level from basic tutorials. It had elements which would be useful for most practical sites like user registrations and making CRUD views.

    Honestly, I don’t like most video tutorials myself as they need a considerable amount of time to watch. However, if they come with a full transcript then I can skim through the text and decide if it contains tips which are worth watching on video. Sometimes, the additional commentary explaining the context is well worth the watch.

    So, I set out to create Steel Rumors as something that everyone including me would enjoy watching. But it turns out creating the transcript is much harder than recording a quick video. In fact, it gets monotonous at times (I really sympathise those who work in Medical Transcription!).

    The videos also get difficult to record in a longer, complex project such as this. I don’t edit out any mistakes or ...

    Continue Reading →
  3. Building a Hacker News clone in Django - Part 3 (Comments and CRUD)

    You are reading a post from a four-part tutorial series

    It feels like ages since part 2 was out. Meanwhile, the movie Man of Steel has actually been released. So there is really no need to check for rumors about what that movie is all about. Probably the industry is now abuzz with rumours about its sequel instead.

    In this tutorial, I would be showing how to use features like comments and CRUD views which are integral to a social site. You can choose to watch the video or read the step by step description below or follow both. The goodies pack which was introduced in the last part has been updated and would be used again to save time to create templates.

    This video would be a continuation of the previous video and I recommend watching it. Click on the image below to watch the screencast or scroll down to read the steps.

    Screencast

    Enjoyed this tutorial? Then you should sign up for my upcoming book “Building a Social News Site in Django”. It tries to explain in a learn-from-a-friend style how websites are built and gradually tackles advanced topics like testing ...

    Continue Reading →
  4. Building a Hacker News clone in Django - Part 2 (User Profiles and Registrations)

    You are reading a post from a four-part tutorial series

    It has been more than a week since the first part of this tutorial series was posted and I’ve been getting positive feedback from several channels. Ironically, it was extremely popular on Hacker News. It was even translated into Chinese.

    To be sure, the objective was not to create a full featured clone of any website. The real objective is to learn Django using a medium-sized project that utilises it to the fullest. Many tutorials fall short of bringing together various parts of Django. Compared to a microframework like Flask (which is also great, btw), Django comes with a lot of batteries included. If you are short on time, this makes it ideal for completing an ambitious project like this.

    This tutorial would show you how to implement social features like supporting user registration and profile pages. We will leverage Django’s class based views for building CRUD functionality. There is a lot of ground to be covered this time.

    As before, there is a text description of the steps if you do not prefer to watch the entire video. There ...

    Continue Reading →
  5. Building a Hacker News clone in Django - Part 1

    You are reading a post from a four-part tutorial series

    There is no better way to learn something than to watch someone else do it1. So, if you have been waiting to go beyond the basics in Django, you have come to the right place.

    In this video tutorial series, I would take you through building a social news site called “Steel Rumors” from scratch in Django 1.5. In case you don’t like videos and prefer to read the steps, you can find them here too.

    Even though we will start from the basics, if you are an absolute beginner to Django, I would suggest reading the tutorial or my previous screencast on building a blog in 30 mins

    The completed site would support user signups, link submissions, comments, voting and a cool ranking algorithm. My approach would be to use as many builtin Django features as possible and use external apps only when absolutely necessary.

    Check out a [demo of Steel Rumors][demo] yourself.

    Click on the image below to watch the screencast or scroll down to read the steps.

    Screencast

    If you liked this tutorial, then you should ...

    Continue Reading →
  6. Easy and Practical Web scraping in Python

    This post is inspired by an excellent post called Web Scraping 101 with Python. It is a great intro to web scraping to Python, but I noticed two problems with it:

    1. It was slightly cumbersome to select elements
    2. It could be done easier

    If you ask me, I would write such scraping scripts using an interactive interpreter like IPython and by using the simpler CSS selector syntax.

    Let’s see how to create such throwaway scripts. For serious web scraping, Scrapy is a more complete solution when you need to perform repeated scraping or something more complex.

    The Problem

    We are going to solve the same problem mentioned in the first link. We are interested in knowing the winners of Chicago Reader’s Best of 2011. Unfortunately the Chicago Reader page shows only the five sections. Each of these sections contain award categories e.g. ‘Best vintage store’ in ‘Goods & Services’. Within each of these award category pages you will find the winner and runner up. Our mission is to collect the names of winners and runner ups for every award and present them as one simple list.

    The Setup

    Start python, IPython, bpython or any other interactive python interpreter ...

    Continue Reading →
  7. Moving Blogs to Pelican

    Redesigning a site takes a lot of planning. I usually take it as an opportunity to study what is the state of the art and implement many long standing items from my wish list. So this post will be a lot more than explaining why I moved to Pelican from Jekyll.

    Background

    I had stopped using Wordpress about two years back. I was a long time user of Wordpress and had even written some plugins. But I was afraid that whatever I had written was turning into a binary blob in some database.

    Don’t believe me? Just open your Wordpress database tables in phpmyadmin or any other tool. If you use Microsoft Word, be prepared to get shocked seeing a lot of unnecessary tags like <SPAN>, class names like class=MsoNormal or converted punctuation marks like &lsquo;. Even web-based composers add a lot of horrible markup. I even tried using the plain text editor with Markdown markup. But something would still get mangled somehow.

    Another major annoyance was that Wordpress had a huge attack surface. Everytime someone finds out a Wordpress exploit, your site is at risk. Only way to secure your content was to take frequent backups and ...

    Continue Reading →
  8. Treeify - Converting Tree Data Structures

    Some of the most interesting algorithms in Computer Science are involving trees. They are simple and often leverage recursion. For instance, pre-order traversal of a tree, of any complexity, can be written as follows:

    void preorder(tree t)
    {
            if(t == NULL)
                    return;
            printf("%d ", t->val);
            preorder(t->left);
            preorder(t->right);
    }
    

    For a hobby project, I was faced with an interesting problem of converting a flat representation of a tree into a nested data structure. A flat representation of a tree looks like this:

    0
    0
    1
    1
    2
    3
    2
    1
    

    Each number refers to the nesting level within a tree. After conversion to a nested structure, it should look as follows (square brackets is the Python syntax for a list):

    [ 0,
      0,
      [ 1,
        1,
        [ 2,
          [ 3 ],
        2],
    1]]
    

    Tree

    I expected this algorithm to be fairly easy to find, but I didn’t have much success with Google. So, as any self respecting programmer would, I rolled up my sleeves and wrote a Python implementation:

    def treeify(cs):
        cur = 0
        tree = []
        stack = [tree]
        for c in cs:
            if c['level'] > cur:
                l = [c]
                stack[-1].append(l)
                stack.append(l)
            elif c['level'] < cur:
                while 1:
                    stack.pop ...
    Continue Reading →
  9. Buying Kesar in Kashmir

    One of the most adventurous things we did after marriage was to go to Kashmir for Honeymoon. Right opposite the Mangalore STP office we have Swastika Tours, a friendly operator whom we have trusted for many tours in the past. In 2008, when we approached him we had all sorts of exotic places in our mind like Maldives, Mauritius or Europe.

    But with the memory of the Tsunami fresh in our minds, we quickly ruled out all islands and sea facing locations. The hill-stations and snow covered locales in the northern hemisphere remained. But it was Santosh from Swastika who planted the idea of Kashmir in our minds. In 2007, Kashmir was considered to be a dangerous place to visit, thanks to the media reports of fresh gun fires or terrorist attacks. We were hesitant. “Why not?”, he asked, “My sister just visited the place and she liked it better than her Switzerland trip. It is completely safe these days.” We looked at each other silently. We both knew that we were up for the challenge.

    The one week Kashmir trip indeed turned out to be one of the best trips we have ever had. It was a land completely ...

    Continue Reading →
  10. The Last Drop on the Planet

    Chaos often breeds life, when order breeds habit.” — Henry B. Adams

    It was a breezy, luminescent and quiet evening in planet Terra. Perhaps too quiet for an eventful day such as this. Perhaps that’s why emperor Kilter ordered a Pan-D911. Soon random bright spots popped all over the planet like an attack of pimples. Soon it smeared itself onto millions of other bright dots turning into something like an attack of rash.

    Like a huge tidal wave the dots arose and swiftly spiralled upward into the cloudy magenta skies. With militaristic precision, the dots arranged themselves into concentric rings in space. From Terra, it was a magnificent spectacle. However, it didn’t impress the Queen, Triara. Made of sixty billion nanobots, Triara was by far the most exquisitely complex being in their planet. That meant she was female and extremely attractive, not to mention that she was undoubtedly their Queen. Even though Kilter was called the mighty Emperor and launched vain crusades that displayed his prowess, it was obvious that it was the Queen upon whom the future course of events rested upon. She scoffed at this ostentatious waste of Nino. Nino, being the hydrocarbon fuel, which powered everything ...

    Continue Reading →

« Page 2 / 17 »