Category Archives: Coding

If you are getting the following error when installing python packages using PIP or easy_install, don’t worry. You have come to the right place for solution.

First make sure you have developer tools installed. You can install them by executing the following command in terminal

xcode-select --install

The clang errors are due to changes introduced in Xcode 5.1 and due to the way the Apple-supplied system Python 2.7 is built. You can tell them to shut up by adding these environment variables in terminal.

Django allows method calls inside template system. Though this is an useful feature, some of the methods will have side effects. Mostly the ones that alter data.
Say, for instance, you have a UserAccount object that has a delete() method. If a template includes something like {{ account.delete }}, where account is a UserAccount object, the object would be deleted when the template is rendered!

To prevent this, set the function attribute alters_data on the method:

def delete(self):
# Delete the account
delete.alters_data = True

The template system won’t execute any method marked in this way. Continuing the above example, if a template includes {{ account.delete }} and the delete() method has the alters_data=True, then the delete() method will not be executed when the template is rendered. Instead, it will fail silently.

$ and ^ are regular expression characters that have a special meaning: the caret means “require that the pattern matches the start of the string,” and the dollar sign means “require that the pattern matches the end of the string.”

For example consider the following url pattern

1

2

3

urlpatterns=patterns('',

url(r'^hello/$',hello),

)

Without the dollar sign at the end it will match any url starting with hello like

Django traceback is a very helpful tool in Django development. It saves us from the boring tasking of writing print statements to track variables.

Traceback doesn’t kick when there is no error. There may be no coding errors but there is a flaw in our application logic which we want to debug. In such cases we can trigger Django traceback by adding assert False in our code.