shabda
Comments
Reactions

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..
Topics : django rambling tips
shabda
Comments
Reactions

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.

  1. aggregate
  2. annotate

When you are have a queryset you can do two operations on it,

  1. Operate over the rowset to ...

more info..
shabda
Comments
Reactions

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..
Topics : tips
shabda
Comments
Reactions

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..
Topics : django tips book

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 ...

more info..
Topics : django tips
shabda
Comments
Reactions

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.)

  1. User's request comes to Apache etc.
  2. Apache sends request to django.core.handlers.wsgi via mod_wsgi.
  3. A list of request and response middleware callables is created.
  4. Request middleware is applied. If it sends a response, it is returned to the user.
  5. urlresolvers.resolve finds the view funcion to ...

more info..
Topics : django tips
shabda
Comments
Reactions

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 ...

more info..
Topics : python tips
shabda
Comments
Reactions

Generating pseudo random text with Markov chains using Python

By : Shabda Raaj

First the definition from Wolfram

A Markov chain is collection of random variables {X_t} (where the index t runs through 0, 1, ...) having the property that, given the present, the future is conditionally independent of the past.

Wikipedia is a little clearer

...Markov chain is a stochastic process with markov property ... [Which means] state changes are probabilistic, and future state depend on current state only.

Markov chains have various uses, but now let's see how it can be used to generate gibberish, which might look legit.

The algorithm is,

  1. Have a text which will serve as the corpus from ...

more info..
Topics : seo algorithms

Django-subdomains - Easily create subscription based subdomains enabled webapps

By : Shabda Raaj

A common goal in web application development is creating subscription based application, where users can use their domains.

For example,
1. Basecamp allows you to manage your project, and gives users as subdomain like xyz.grouphub.com 2. Blogger goes a step further, and allows you to use arbitrary domains with your domain, using Cnames.

django-subdomains is an application which makes both these possible, and allows you to charge the users using paypal.

More details are available here, but to whet your appetite, some details


  1. You want to allow users to create accounts.
  2. Users should get a subdomain for their ...

more info..

Web development companies working with Django

By : Shabda Raaj

At Agiliq, we work with some of the best web development agencies. I wanted a list of the other building web applications with Django, here is such a list, in no specific order.

  1. Additional View Tasmania, Australia
  2. Lincolnloop Colorado, USA
  3. Illusion Factory California, USA
  4. Syntress Chicago, USA
  5. Torchbox Oxfordshire, UK
  6. Liberiun Brazil
  7. Yed-Prior Now known as Djangostars Ukraine
  8. Tatum Interactive New York, USA
  9. Menttes Argentina
  10. Tarams Bangalore, India
  11. Cubedroot Ireland

And of course Agiliq

Additions:

  1. Adoleo Texas, USA
  2. Siu Design United Kingdom
  3. Web Collective Seattle, USA
  4. Digital Eternal Malaysia
  5. Revolution Systems Lawrence, Kansas, USA
  6. Setaris New York City, NY, USA ...

more info..
Topics : business
shabda
Comments
Reactions

Constraint programming in Python

By : Shabda Raaj

Imagine this, you want to solve a problem, the algorithm for which you do not know. You just know the problem.

From wikipedia,
Constraints differ from the common primitives of imperative programming languages in that they do not specify a step or sequence of steps to execute, but rather the properties of a solution to be found.

Assume that there exists an alternate world where you only need to specify the problem, the computer will find out an algorithm to find it, even better if could you write it in Python.

Stop assuming it hapens every day, and this is ...

more info..
Topics : algorithms
shabda
Comments
Reactions

Django with Mysql and Apache on EC2

By : Shabda Raaj

What is EC2

Unless you have been living on Mars these last few years, you are sure to have heard of EC2. Amazon's cloud offering, it offers infinite scalability. Using EC2, you can bring up any number of machines online at minutes notice, and after you are done with them, bring them down.

How does EC2 work?

A EC2 machine is nothing but a bare machine. An Amazon Machine Image (AMI) is a machine bundled as an Image, with preconfigured software which you can start at moments notice. We will take a AMI with a basic Ubuntu installed, and ...

more info..
Topics : web2.0 Amazon mysql
shabda
Comments
Reactions

How to build a Facebook app in Django

By : Shabda Raaj

Facebook has a simple and robust API which allows users to build applications for the Facebook platform. We being the intelligent developers will use the superb Django framework to build our application.

The completed code for this is available at https://svn.uswaretech.com/favlang/. The completed application is deployed to facebook here.

How does a Facebook application work?

  1. The users make a request to apps.facebook.com/yourapp/page1/
  2. The Facebook servers make a request to yourserver.com/page1/
  3. You get the requests and can make calls to Facebook API, and use FQL to query the Facebook tables.
  4. You ...

more info..
Topics : facebook

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,

  1. You make a SetExpressCheckout request to Paypal, passing your credentials and and the amount you want to charge etc.
  2. Paypal returns an response with ACK of SUCCESS and token which you need ...

more info..
Topics : tips paypal

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..
Topics : tips

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

  1. Sometimes looks more professional. Users will prefer someblog.wordpress.com over wordpress.com/someblog.
  2. 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.
  3. Your users can point a Cname to their subdomain to use domain of their choice with their subdomain.

Disadvantages of subdomain

  1. When you need ...

more info..
Topics : tips

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

  1. A form which knows how to render itself as Html.
  2. A form which knows how to validate data on the server side.
  3. 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..
Topics : tips forms

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 ...

more info..
Topics : tips

Building SEO optimised Django web applications

By : Shabda Raaj

This is an article about building SEO, optmised web applications with Django. I assume you already have an idea how Seo works. We will take the example of a hypothetical Blog app to explain the suggestions made.

Without further ado, here are the tips.

Basic

  1. Use beautiful URLs.
  2. Learn the difference between HTTP 301 and HTTP 302 redirects.
  3. Layout content in a SEO friendly way.
  4. Create a sitmaps.

Not so obvious

  1. Use the Admin to allow end users to update fields.
  2. Do not get your Url structures too deep.
  3. Create a robots.txt file.
  4. Link to your pages wisely.
  5. Minimise ...

more info..
Topics : seo

An Interview with Adrian Holovaty - Creator of Django

By : Shabda Raaj

Adrian Holovaty is the co-creator of Django, author of the Django book and is currently the BDFL of Django along with Jacob Kaplan-Moss. He studied journalism at University of Missouri–Columbia and has worked with many news sites including Lawrence Journal World and Washington Post. He currently works at EveryBlock, a startup he founded.


Shabda: Would you tell a little about yourself? You majored in Journalism, how did you move to Programming?

Adrian: Sure! I have a dual background in journalism and computer science. I intended to get a degree in journalism and a minor in computer science, but things ...

more info..

An Interview with Jacob Kaplan-Moss - Creator of Django

By : Shabda Raaj

Jacob Kaplan-Moss Jacob Kaplan-Moss is the co-creator of Django along with Adrian Holovaty, as well as the author of the Django Book. He has been involved with Django since before it was called Django. He is currently employed at Whiskey Media where his job is hacking at Django. He blogs on Jacobian.org. He graciously agreed to be interviewed at the 42topics blog.


Shabda: Would you tell a little about yourself? How did you get started with Django? What other software/applications have you worked with. (Both OSS and otherwise)?

Jacob: So a bit about me: I grew up in Silicon Valley ...

more info..

An idea a day - A geographical wiki

By : Shabda Raaj

This is an article in the Five Startup Ideas series at the 42topics blog. In his essay, Ideas for Startups, Paul Graham argues that ideas are not a critical factor for success of startups. Although I do not believe that ideas are worthless, as many people do, I believe that they are not any where near as important as execution. So to prove my point, I am giving away 5 startup ideas in next five days. All of them describe a problem, its solution, the technology involved, the competition and market size. If you are not a hacker, and want ...

more info..

An idea a day - Alternative to GAE

By : Shabda Raaj

This is an article in the Five Startup Ideas series at the 42topics blog. In his essay, Ideas for Startups, Paul Graham argues that ideas are not a critical factor for success of startups. Although I do not believe that ideas are worthless, as many people do, I believe that they are not any where near as important as execution. So to prove my point, I am giving away 5 startup ideas in next five days. All of them describe a problem, its solution, the technology involved, the competition and market size. If you are not a hacker, and want ...

more info..

An idea a day - Remotely hosted Analytics solution

By : Shabda Raaj

This is an article in the Five Startup Ideas series at the 42topics blog. In his essay, Ideas for Startups, Paul Graham argues that ideas are not a critical factor for success of startups. Although I do not believe that ideas are worthless, as many people do, I believe that they are not any where near as important as execution. So to prove my point, I am giving away 5 startup ideas in next five days. All of them describe a problem, its solution, the technology involved, the competition and market size. If you are not a hacker, and want ...

more info..
© Agiliq, 2009-2012