Aug 1, 2018

Change password of a user in Django

Start by opening the Django shell from your terminal

> python shell

Then inside the Django shell, first get hold of that user object, then change the password and save.

Jan 19, 2017

Django HTTP only CSRF cookie

Django sets a CSRF cookie to protect against cross site request forgeries. By default this cookie is set to be accessible to JavaScript on your web page. That means, the cookie will be accessible to a malicious script running on this page, too. ...

Dec 21, 2016

Django query time using the connection module

The Django connection module keeps track of recent queries. To see the SQL code and time taken to run the queries, have a look at the connection.queries field.

from django.db import connec...
Dec 13, 2016

Reading list of values from django request object

Sometimes an array of values is sent as a param of a GET or POST request to the server. For example, when you have a multiple select or a group of check boxes in the front end, the form submission URL may look like this:

Use getlist to r...

Nov 28, 2016

Django F expression for increment

Django F expressions can be used to manipulate object fields in the database without pulling them out to the application layer. An use case is when a field needs to be incremented. The less then ideal way to do so wou...

Jan 27, 2016

Configuring unicode in Gunicorn upstart

Gunicorn is a good tool for deploying django websites on Ubuntu (and other Linux) servers. However, servers are often not configured to support unicode by default. Some environmental variables have to be set in order to enable unicode handling. Set these environmental variables in the upstart fil...