We are a small, intelligent App development studio. We love "Building Amazing Apps", solving problems and cultivating strong relationships with our clients.
Common testing scenarios for Django app.
By : Akshar Raaj
People are often confused regarding what tests to write. Let's look into some scenarios for which tests can be written.
Setting up the project
We start a Django project inside a virtual environment. In this post we would be using django 1.4.
(dj)~/play/dj$ django-admin.py startproject testcases
Let's start an app named blog.
(dj)~/play/dj/testcases$ python manage.py startapp blog
We will have the following model in blog/models.py:
class BlogEntry(models.Model):
title = models.CharField(max_length=100)
text = models.TextField()
is_published = models.BooleanField(default=True)
user = models.ForeignKey(User)
We ...
more info..Logging in Django
By : Javed Khan
This is a talk I gave at Agiliq on 21-March-2013 as a part of the Hyderabad Python Meetup Group
more info..Serving static files in Django
By : Akshar Raaj
Serving static files, especially during development, is frequently a pain point. In this post, we will discuss the various settings and directory structure and how they interact with each other. Let's start with development when you have DEBUG = True.
We will create a Django project from scratch so that we are fully aware about what file in what directory we are talking about. So, this blog post will be a little longer than it should be. We will try these things with Django 1.4, but these will work on Django 1.3 as well. I have not tested ...
more info..Two Scoops of Django: Review
By : Shabda Raaj

Two scoops of Django is the new book on Django best practices by Daniel Greenfeld and Audrey Roy. I just finished reading it and found it extremely useful.
The book is a collection of tips, their justification and code organized in logical areas. I have been using Django since 2008, but I still found a few tips which were new to me and many which served as good reminder. At about 200 pages, its comprehensive but not overwhelming. If you are an advanced Djangonaut, you can read it in a weekend (And you probably are using all its recommendations anyway ...
more info..Easy client side form validations for Django: Django Parsley
By : Shabda Raaj
Parsleyjs is a JavaScript library to do client side data validations.
It does this in a non-intrusive way via adding a data-* attributes to form fields. Check it out, it's really slick.
Django forms do a great job of server side data validations. By integrating Parsley with Django form, you get good client side data validations as well. Get the app here.
Some design considerations
When I started writing this app I wanted to make it really easy to use. My first thought was to make this a filter or a template tag which would have allowed you to ...
more info..Not exactly, not exactly tim the enchanter
By : Javed Khan
I've been putting off writing about my experience with django form wizard for some time now. I came across this blog post by Kenneth Love which finally compelled me to write this down.
About Django Form Wizard:
Form Wizard can be handy when you have a huge form, and you want to make it less intimidating to the user by splitting it into multiple steps.
If you have glued multiple forms together with sessions or whatnot and it
turned out to be a mess, you now what I'm talking about :)
Think surveys, checkouts, lengthy registrations etc.
The class ...
more info..The missing documentation for django.utils.datastructures
By : Thejaswi Puthraya
Note
django.utils.datastructures is intentionally not documented by the django core devs because it is an internal API and is liable to change without any notice. This file is not governed by django's lenient backwards-compatible policy. You have been sufficiently warned!
With the note out of the way, let's look at the interesting datastructures in this file. You may ask why we should learn about those when we shouldn't be using them? Reading code is the best way of learning and this file has some beautiful code.
MergeDict is the first of the datastructures in the ...
more info..Rails for Django developers
By : Shabda Raaj
My presentation at Pycon India 2012
Download it from here more info..
Dropbox file upload handler for django
By : Thejaswi Puthraya
Dropbox announced new pro plans last week and some accounts have had their storage size doubled. Wouldn't it be wonderful if we could upload all our files to dropbox from our django webapp?
In this post, I write a custom file upload handler that will upload files from our application to dropbox.
Let us see how to use the custom file upload handler.
Install the Dropbox Python SDK before you setup your django app to handle the file uploads.
In your settings.py, add the following attributes (with the values filled):
DROPBOX_APP_KEY = "" DROPBOX_APP_SECRET_KEY = "" DROPBOX_APP_ACCESS_TOKEN = "" DROPBOX_APP_ACCESS_TOKEN_SECRET = "" # Optional values below # The ...more info..
Deploying Django apps on Heroku
By : Shabda Raaj
Deploying Django apps on Heroku:
Read this first: http://devcenter.heroku.com/articles/django.
This is a great article by the Heroku. I am just filling in some more details and making this step-by-step.
- Get your Django project code.
-
Create a virtualenv with a no-site-packages command ::
virtualenv vent --no-site-packages
-
Install Django, psycopg2 (postgres connector), gunicorn and any other required Django libraries.
- Confirm that you have all the required libraries and you can run your code locally using
manage.py runserver. -
Create a requirement.txt by using ::
pip freeze > requirements.txt
-
Make sure you have a requirements.txt at the root ...
Deploy Django App in 5 Easy Steps
By : Saket Bhushan
So you just bought a new VPS, have installed Ubuntu and want to deploy your django app, GREAT!! We shall get your app, up and running in 5 easy steps, using best(arguably) of tools available. The post is targeted to audience who are new to deployment arena, but assumes you are comfortable with developing basic django apps. We shall be using gunicorn as our server and nginx nginx as our reverse proxy and static hanlder. Here we go:
1. Login and OS Updation:
$ ssh root@{your_ip}
# apt-get update
# apt-get upgrade
# apt-get dist-upgrade
# dpkg-reconfigure tzdata #choose your time zone
2 ...
more info..Dynamically attaching SITE_ID to Django Caching
By : Anoop Thomas Mathew
It would be useful and convenient, if you have an automatic way to add the SITE_ID, especially, when you have multiple sites running on the same deployment. Django provides a cache prefix function KEY_FUNCTION in settings which can be used to achieve this.
Just follow the following steps, and your cache, automatically prepends SITE_ID to the cache key, making it unique across multiple sites.
-
Put the following into the settings file.
CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'cache_table', KEY_FUNCTION = ‘projectname.appname.modulename.functionname’, } }
-
Write a function to get current site id, say, get_current_site(), which returns current ...
Deploying Django apps on Heroku
By : Shabda Raaj
Read this first: http://devcenter.heroku.com/articles/django.
This is a great article by the Heroku. I am just filling in some more details and making this step-by-step.
Get your Django project code.
Create a virtualenv with a no-site-packages command
virtualenv vent --no-site-packages
Install Django, psycopg2 (postgres connector), gunicorn and any other required Django libraries.
Confirm that you have all the required libraries and you can run your code locally using manage.py runserver.
- Create a requirement.txt by using
pip freeze > requirements.txt
Make sure you have a requirements.txt at the root of your repo. Heroku uses ...
How to use pep8.py to write better Django code
By : Shabda Raaj
Here is another or screencast I created for my "Getting Started with Django" series. Like this? Email us on what would you like to see.
(Watch in fullscreen.)
more info..Screencast: Django Tutorial Part 1
By : Shabda Raaj
Django Screencast Tutorial 1 from Shabda Raaj on Vimeo.
I am creating screencasts for Django tutorial and other Django videos. Here is part 1. Liked this? Leave me a comment or email me and tell me what would you like me to create screencasts for.
(Watch the screencast in full screen mode.)
more info..How and why to use pyflakes to write better Python
By : Shabda Raaj
Here is another of the screencasts I created for "Getting started with Python" series. Liked them? Let me know what else would you like me to create screencasts about?
more info..Getting started with South for Django DB migrations
By : Akshar Raaj
South is a migration tool used with Django.There will be times when you would be adding fields to a model or changing the type of field (eg: Field was an IntegerField and you want to change it to FloatField). In such cases syncdb doesn't help and South comes to your rescue.
There were times when i tried "python manage.py migrate southapp", got some error and then tried "python manage.py migrate southapp 0001 --fake". In some cases, that worked. When it did not work, i tried something else and so on. There were confusions regarding what --fake ...
more info..Behind the Scenes: Request to Response
By : Thejaswi Puthraya
In the previous installment of "Behind the Scenes", we saw how the control flows from Form to File Storage. Today, we are going to see how the application reacts from request to response.
In this post, we are going to assume that we are using django's inbuilt runserver. The flow doesn't change much for other WSGI servers available.
When you invoke the runserver management command, the command line options are validated and an instance of WSGIServer is created and passed the WSGIRequestHandler, which is used to create the request object (WSGIRequest). After the request object is created and ...
more info..Haml for Django developers
By : Shabda Raaj
Haml is taking the Ruby(and Rails) world by storm. Its not used as heavily by Python(and Django) developers as the Python solutions aren't as mature. I finally gave Haml a try and was pleasantly surprised how easy it was.
The most mature Python implementation of Haml is hamlpy, which converts the hamlpy code to Django templates. Others are shpaml and GHRML
Lets look at some templates from Django tutorial
{% if latest_poll_list %}
<ul>
{% for poll in latest_poll_list %}
<li><a href="/polls/{{ poll.id }}/">{{ poll.question }}</a></li>
{% endfor %}
</ul>
{% endif %}
Here is this template converted to Haml
-if ...Behind the Scenes: From HTML Form to Storage
By : Thejaswi Puthraya
In this post, we are going to see what happens behind the scenes when a file is uploaded to a django powered web application.

An HTML form with a file input (atleast one) and encoding set to multipart/form-data is submitted. The MultiPartParser parses the POST request and returns a tuple of the POST and FILES data (request.POST, request.FILES). The MultiPartParser processes the uploaded data using the File Upload Handlers objects (through the new_file, receive_data_chunk and upload_complete methods). The request.FILES values are a sequence of instances of UploadedFile.
In the django form, we pass the request.FILES ...
more info..Real time applications with Django, XMPP and StropheJS
By : Javed Khan
TL;DR:
- django-pubsub allows you to create Twitter like real-time updates for your models with Admin like ease.
- Demo at http://chat.agiliq.com/pubsub/
- Code at https://github.com/agiliq/django-pubsub
Introduction:
PubSub is a XMPP extension which allows publishing and subscribing to events. This is useful when you instantly want to notify many clients about something interesting happening on your server.
Quoting the authors of PubSub specs:
The protocol enables XMPP entities to create nodes (topics) at a pubsub service and publish information at those nodes; an event notification (with or without payload) is then broadcasted to all ...
Seven reasons why you should switch to Vim
By : Javed Khan
So you want a better IDE for developing django, huh? Why not give good old vim a try?
Use pathogen to maintain your vim plugins (and sanity).
Using this, you can clone the repositories listed here to .vim/bundle/ and start using them
right away.
Also, consider adding your .vimrc and .vim to a repository. Include .vimrc inside .vim and
symlink .vim/.vimrc to ~/.vimrc to version control your .vimrc.
My vim files can be found here. Also, here's an imgur album demonstrating these plugins in action.
1. Syntax highlighting for django templates
Starting from vim 7.1, syntax ...
more info..Importing wordpress
By : Shabda Raaj
We now have a way to import wordpress to blogango, and all our old posts are on this blog.
Thanks for reading.
more info..Getting trending Github projects via YQL
By : Shabda Raaj
Github.com/explore allows you to see the trending Github topics. They use repopular.com for this, which use twitter retweets to find out the popular Github repos.
Since neither Repopular, nor Github have a RSS of these trending repos, I wanted to get a list of these. Here is how easy it is with YQL.
How we do it
-
Go to YQL console. Give the SQL query to get the data from the webpage.
-
where url="repopular.com" and css="div.pad a"is the magic which select the webpage, and also what DOM elemenst we are interested in ...
- Deploying django using docker
- Common testing scenarios for Django app.
- Logging in Django
- Serving static files in Django
- Two Scoops of Django: Review
- Introduction to Python Workshop on February 15th, 2013
- Easy client side form validations for Django: Django Parsley
- MoreApps - Android Library Project: Open Sourced
- Tutorial: Building a Chrome app
- Password Generator App: Open Sourced
- June 2013
- April 2013
- March 2013
- February 2013
- January 2013
- November 2012
- October 2012
- September 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- October 2011
- September 2011
- July 2011
- June 2011
- April 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- June 2010
- April 2010
- March 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- April 2009
- March 2009
- February 2009
- November 2008
- October 2008
- June 2008
- May 2008
- April 2008
Deploying django using docker
By : Javed Khan
In this blog post we'll take a look at Docker and discuss ways to deploy django using docker.
About Docker:
Docker is a tool that helps you manage lxc containers and images. You can create an image, launch container from the existing image, attach to a running container, and generally play around with the containers.
The most important benefit of using docker and containers in general is that you have a clean, hygeinic and portable runtime enivorment for your app. This means you don't have to worry about missing dependecies, packages and other pain points during subsequent deployments ...
more info..