21 Oct, 14

Django Uwsgi Nginx 504 Gateway Timeout

I had a long running process (data import) and encountered 504 Gateway Timeout error. I use Nginx / uwsgi pair to serve my Django app. After doing some research it turned out that the problem is in uwsgi_read_timeout directive. Directive sets the amount of time for upstream to wait for a ...

Read now
09 Oct, 14

AngularJS plus Django: A match made in heaven

I've just finished watching "AngularJS plus Django: A match made in heaven" DjangoCon US 2014 talk by Nina Zakharenko (Video | Slides) and it was quite helpful. Since I'm working with API's and mobile / angular apps a lot, I just made some helpful Django + AngularJS related notes that came out of ...

Read now
19 Sep, 14

Improving Number of Queries Generated by Django Comment's render_comment_list Template Tag

One of my Django apps uses Django Comments. To show a list of comments on a page I use this simple built-in template tag:

1
  1. {% render_comment_list for object %}

All is fine, but I noticed that it loads user object per every comment line. So if you have 50 comments on ...

Read now
08 Sep, 14

AngularJS Style Guide

I've just stumbled upon a very nice style guide for AngularJS on Github: https://github.com/johnpapa/angularjs-styleguide by John Papa. In the guide you'll find recommended approaches to your AngularJS code organisation in order to provide consistency through good practices. A very useful material for everyone who's already got ...

Read now
03 Sep, 14

Make Django and AngularJS play nicely together

Been working a lot with AngularJS and Django recently. To make them play nicely together one of the first things you need to do in your Angular App is to enable CSRF support and send X-Requested-With header, do it like this:

1
2
3
4
5
6
  1. var app = angular ...
Read now
07 Jun, 14

Stop PIP from re-downloading same packages over and over again

PIP has a habit of re-downloading same packages every time you hit pip install package_name. That's not so cool, especially, when you deploy packages from requirements.txt and one of the packages failed to build, restarting pip install -r requirements.txt would lead pip to redownload all the packages again ...

Read now
01 Jun, 14

Cleanup Files (and Images) On Model Delete in Django

In Django, if your model has Filefield / Imagefield, when it's get deleted it doesn't delete attached files by default. To fix that you need to do two steps: 1) Add filecleanup function, that'll take care of deleting files attached to a model:

 1
 2
 3
 4
 5
 6
 7
 8 ...
Read now
20 May, 14

Adding a custom extra field to entity / node display

I had a case recently, where I needed to add custom data to the node display and wanted this data to behave like a field, however the data itself didn't belong to a field. By "behaving like a field" I mean you can that field at node display settings and ...

Read now
29 Apr, 14

Run Multiple Django Apps With Celery On One Server With Rabbitmq VHosts

Very often we can have multiple Django apps each running celery and all this is installed on a single server. How do we isolate these separate app's celery workers? The answer is: Simple, if you use Rabbitmq as your broker. Rabbitmq lets us to add multiple virtualhosts, so we can ...

Read now
25 Apr, 14

ERROR: must be owner of extension plpgsql

Today while moving Django/PostgreSQL site between servers and importing an SQL dump into the new location I got a surprising error "ERROR: must be owner of extension plpgsql". I'm already used to PostgreSQL quirks so after a quick search I came to the following solution: Login as postgres user ...

Read now