Comments
Reactions

Django for a Rails Developer

By : ashok

This is not yet another Django vs Rails blog post. It is a compilation of notes I made working with Django after having worked on Rails for years.

In this post I want to give a brief introduction to Django project layout from a Rails developer point of view, on what is there, what is not there and where to look for things. It should help a rails developer working on django be able to find the necessary files and underatnd the layout of the project files.

Once you have both the frameworks installed on your system you can create ...

more info..
Topics : rails django python
shabda
Comments
Reactions

The magic of metaclasses in Python

By : Shabda Raaj

Metaclasses are a way for you to have a class act as the template for another class. They are simlar to a classfactory, in that they create new classes. In words of Tim Peters Metaclasses are deeper magic than 99% of people are going to need.

However, in right hands they can be a potent tool, in particular Django uses metaclasses beautifully to create very beautiful declarative models. Without further ado, here is a very simple (and very wrong) metaclass example.

class Z(type):
    def __new__(cls, name, bases, attrs, ):
        print cls, name, bases, attrs

class A(object):
    __metaclass__ = Z ...

more info..
Topics : Uncategorized

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

  1. Returns a tuple of (openfile, filename) if it can find the template.
  2. 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..
shabda
Comments
Reactions

Django gotchas

By : Shabda Raaj

This is announcement about our new work, Django Gotchas, a teeny tiny ebook about commonly occurring gotchas with Django. Here is the readme copied from the project.


Django-gotchas is a collections of gotchas which happen commonly when you are working with Django. They are some errors which I have made commonly or seen others do, these are not the errors which happen because they are hard to reason about, these are those errors which hapen when you close your eyes for a moment when coding.


This is still very much a work in progress, released in the spirit of release ...

more info..
Topics : django book tutorial
© Agiliq, 2009-2012