We are a small, intelligent App development studio. We love "Building Amazing Apps", solving problems and cultivating strong relationships with our clients.
Tools of Pro Django developer - aka What powers dinette and almost every app we write.
By : Shabda Raaj
There are some tools and apps which we use with almost all apps we write, and in particular which, we used for dinette. Here they are broken into useful during development, and (also) useful post development.
During Development
Ipython and ipdb
Ipython is a enhanced shell for python. Ipdb similarly add extra capacity to the builtin pdb debugger. It is extremely convenient to drop into a ipython shell right where a complex piece of code is being hit.
from IPython.Shell import IPShellEmbed
ipython = IPShellEmbed()
ipython()
Of course ...
more info..Using bpython shell with django (and some Ipython features you should know)
By : lakshman
What is bpython?
bpython is a fancy interface to the Python interpreter for Unix-like operating system.
says the bpython home page. It provides syntax highlighting, auto completion, auto-indentation and such stuff.
Unlike iPython, which implements then entire shell functions and emulates the standard python shell, and adds enhancements, bpython just adds features on top of the existing python shell functionality, using the curses module.
The "killer feature" of bpython is, as you can see from the image above, the IDE like prompting of the function parameters and the doc string of the function dynamically. I have always thought, what IntellijIDEA ...
more info..Django quiz
By : Shabda Raaj
A quick django quiz. Answers available tomorrow. Get it as a text file (django-quiz) or on google docs or read below.
### Easy
1. You have a class defined as
class Post(models.Model):
name = models.CharField(max_length=100)
is_active = models.BooleanField(default=False)
You create multiple objects of this type. If you do
Post.objects.get(is_active=False),
what exceptions is raised?
a. MultipleObjectsReturned
b. ManyObjectsReturned
c. SyntaxError
d. MultipleModelReturned
e. ManyModelReturned
2. Where is the function render_to_response defined?
a. django.views
b. django.shortcuts
c. django.templates
d. django.contrib.templates
e. django.contrib.shortcuts
3. What is the ...Writing your own template loaders
By : Shabda Raaj
Django has three builtin template loaders which are used to get the templates for rendering.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
# 'django.template.loaders.eggs.load_template_source',
)
Writing your template loader is a awfuly easy. It is a callable which
- Returns a tuple of (openfile, filename) if it can find the template.
- Raise TemplateDoesNotExist if the templates cannot be found.
The simplest template loader can be
from django.template import TemplateDoesNotExist
def load_template_source(template_name, template_dirs=None):
try:
return open(template_name).read(), template_name
except IOError:
raise TemplateDoesNotExist, template_name
if you put this to your template loaders directory ...
more info..A response to Dropping Django
By : Shabda Raaj
Brandon Bloom yesterday wrote an interesting post titled dropping Django. Despite a lot of hand waving(We needed a pragmatic template language to replace Django's idealistic one.), it raises some valid questions, so here is a solution to some of them.
No support for hierarchical url creation.
The simplest representation of nested urls I can think of is a nested tuple. Lets represent, the urls for a simple app by,
>>> tree_urls = ('', 'list',
... ('edit/', 'edit', ('auto/', 'edit_auto')),
... ('^add/', 'add'),
... ('delete/', 'delete', ('hard/', 'delete_hard'))
... )
Guess what, urls.py is just a python module which excepts a variable names urlpatterns.
Which means ...
more info..Django aggregation tutorial
By : Shabda Raaj
One of the new and most awaited features with Django 1.1 was aggregation. As usual, Django comes with a very comprehensive documentation for this. Here, I have tried to put this in how-to form.
Jump to howtos or Get source on Github.
Essentially, aggregations are nothing but a way to perform an operation on group of rows. In databases,
they are represented by operators as sum, avg etc.
To do these operations Django added two new methods to querysets.
aggregateannotate
When you are have a queryset you can do two operations on it,
- Operate over the rowset to ...
On Captcha
By : Shabda Raaj
When building public facing websites, spam is a real problem. Captcha has been teated as the first line of defence aginst this problem. If you must use captcha, here are some best practices working with them.
Can you do without one?
A lot of places captcha's are put to filter spam in user generated comment. One of the largest sources of UGC is comments on wordpress blogs. They do not use a captcha, and instead pass all comments through Akismet to verify which comments are spam, and reject the spams. In many cases, such a system would work for ...
more info..Fun with none
By : rohit
(If you are in a hurry, here is the fun part.;) A few days ago, I was working with a nullable field, which wasn't behaving as I expected. So I started a shell, and see how nulls compare.
Funny, not as I expected. (Why is None < 10 True. I thought it would be either False or None or cause an Error?) So python is obviously broken, next steps, see the same thing in some other ... more info..In [1]: NoneIn [2]: None > 10Out[2]: FalseIn [3]: None < 10Out[3]: TrueIn [4]: None == NoneOut[4]: True
Django design patterns
By : Shabda Raaj
This is announcement about our new work, Django design patterns, a ebook about, well, Django design patterns. (Well imagine that!). Here is the readme copied from there.
[Edit] Syntax highlighting and indentation preservation were totally brroken. Fixed now.
Django design patterns is a book about commonly occuring patterns in Django. Not patterns in Gof sense, but patterns in the sense, we work this way, and it works for us. For us it is a ~pattern of work~ sense.
At this point this is just a lot of brain dump from us.
The latest sources are always available from http://github ...
more info..Remote debugging - debugging pesky server only bugs
By : Shabda Raaj
Here is a quick tip. (Obvious if you work with Django for any length of time, but I have seen a few people who are not aware)
You can put debug trace import pdb; pdb.set_trace() in your code, and put it on the server. When you access this view from your local browser, the debug is still hit and you have a debug shell on your server where you can step through. (Obviously this works only if you ran the code via manage.py runserver. But manage.py runserver start the server to listen only on local connections. If ...
Django Request Response processing
By : Shabda Raaj
Have you wondered the steps a users request goes through before being responded to by Django? The answer lies in reading django.core.handlers.base and django.core.handlers.wsgi. Here is a diagram explaining what happens. (Click to enlarge.)
The steps are. (With Apache/Mod_wsgi, similar steps for other setup.)
- User's request comes to Apache etc.
- Apache sends request to
django.core.handlers.wsgiviamod_wsgi. - A list of request and response middleware callables is created.
- Request middleware is applied. If it sends a response, it is returned to the user.
urlresolvers.resolvefinds the view funcion to ...
Better Python package management using source and version control systems
By : lakshman
Thanks to awesome django community, there is plenty of open source django code around.
These packages get updated quite often and if you use it often like we do, you'd have possibly realized the need to manage these packages better.
Thankfully, all python ever needs is the source, and all you need to do is to place the source in the python path.
Most projects use Distributed Version Control Systems like Mercurial and Git, and they come locally with the entire history of the source which provides a lot of control to use any version of the code. For ...
more info..Understanding decorators
By : Shabda Raaj
If you used Django for any length of time, you would have come across the
login_required decorator. You write @login_required before a view, and it
magically becomes accessible only to authenticated users.
Decorators were introduced in python 2.4. PEP 318
is the PEP describing it. At
the simplest decorators are nothing but callables returning other callables, and
the decorator syntax @decorator is nothing but foo = bar(foo), where both
bar and foo are callables.
Let us see some decorators in action.
In [1]: def good_function():
...: print 'I am a good function'
...:
...:
In [2]: def decorator(orig_func):
...: def bad_func():
...: print ...Using Paypal with Django
By : Shabda Raaj
Paypal has a comprehensive API to use their services programatically. The ExpressCheckout API allows you to get the user's details and then process the payments on your servers. They include a SOAP and NVP API. With NVP you do a GET to the Paypal servers with Url encoded values, get responses in plain text and work with them.
The basic flow for ExpressCheckout is something like this,
- You make a SetExpressCheckout request to Paypal, passing your credentials and and the amount you want to charge etc.
- Paypal returns an response with ACK of SUCCESS and token which you need ...
Building reusable Django apps
By : Shabda Raaj
Recently I updated a lot of our old apps to be compatible with Django 1.0 and be reusable. Before we go further, let me define a _ Reusable Django App _.
A Django app is reusable if
* It is app. (That is, it is not a project, and has no settings.py/manage.py.)
* It can be dropped in an existing project, and only places where the project should need editing are `settings.py` `installed_apps` and the projects level `urls.py`.
* It can be used in the project with an arbitrary url prefix.
The updated apps were written initially ...
more info..Using subdomains with Django
By : Shabda Raaj
Django makes using beautiful urls a snap. However using subdomains with Django is not so obvious. Here is an article explaining this.
Advantages of subdomain
- Sometimes looks more professional. Users will prefer someblog.wordpress.com over wordpress.com/someblog.
- If each part of your site is Under a different untrusted users, you might want to give them a separate subdomain, so that if they do Blackhat Seo on their part, the main site is not harmed.
- Your users can point a Cname to their subdomain to use domain of their choice with their subdomain.
Disadvantages of subdomain
- When you need ...
Dynamic forms with Django
By : Shabda Raaj
Newforms, (or forms now) are without doubt one of the coolest features of Django. (Of course after Admin, Localflavor, and many others). Here is some sample code.
class EmployeeForm(forms.Form):
name = forms.CharField()
age = forms.IntegerField()
resume = forms.FileField()
Just this code gives you
- A form which knows how to render itself as Html.
- A form which knows how to validate data on the server side.
- A form which knows how to show the relevant errors.
However think of this scenario,
You need to customise your form depending on values in the Database.
What you want to do is ...
more info..Generating PDFs with Django
By : Shabda Raaj
If your web app creates report chances are you also want this report in PDF form. The Django docs describe a way to generate PDFs using ReportLab. Here is some code from there.
from reportlab.pdfgen import canvas
from django.http import HttpResponse
def some_view(request):
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=somefilename.pdf'
# Create the PDF object, using the response object as its "file."
p = canvas.Canvas(response)
# Draw things on the PDF. Here's where the PDF generation happens.
# See the ReportLab documentation for the full ...- 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
- Todo List App: Open Sourced
- 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

The Unfuddle Tutorial
By : Shabda Raaj
Unfuddle is the tool we use for our non open source development. I have found it to be the best tool for Software Project management, in particular I think it is superior to Basecamp and Assembla.
When you start using Unfuddle, the number of things can seem overwhelming. This tutorial should help you Unfuddle the Unfuddle.
The Unfuddle Glossary
Unfuddle has,
- Projects: Top level Things which need to be done.
- User: People who are working on a given project.
- Ticket: What a
- Milestone: A timed list of
more info..Userworks on.tickets which should be completed before this given time ...