Django 2.0.2 + Python3 + Apache + mod_wsgi

Steps to deploy a Django 2.0.2 project using apache server and mod_wsgi.

I was recently trying to deploy a python 3.5 web application on an EC2 Amazon Linux AMI. I thought it should be a quick process, however it took me some time to make sure all dependencies are pointing to python-3.5 on the machine. Here are some things I did to finally deploy the django project.

NOTE: I am doing this on Amazon Linux and not ubuntu

Check which python version is being used by default

$ python --version

If there are multiple python versions installed on your system, configure your machine to use python3

The following command will ask you to the select the python version you want your machine to point to.

$ update-alternatives --config python

Create a symbolic link for pip/pip3 to point to pip-3.5

I am using Python3.5  so I had to point pip to use pip-3.5.

$ sudo ln -s /usr/bin/pip3.5 /usr/bin/pip

If you need to remove existing symbolic link, just delete /usr/bin/pip

Install httpd

$ sudo yum install httpd-devel

Install mod_wsgi using pip3 command

$ sudo pip3 install --target=/usr/local/lib64/python3.5/site-packages/ mod_wsgi

Add mod_wsgi module to /etc/httpd/modules/

$ sudo ln -s /usr/local/lib64/python3.5/site-packages/mod_wsgi/server/ /usr/lib64/httpd/modules/ 

Create file /etc/httpd/conf.d/wsgi.conf with following contents:

Apache will load wsgi whenever it is started

LoadModule wsgi_module modules/

Restart apache

$ sudo service httpd restart

Configure /etc/httpd/conf/httpd.conf to listen to your host on port 80

NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot /var/www/html/projects/
    ServerName dns-address
    ErrorLog <path/to/store/apache_error.log>
    CustomLog <path/to/store/apache_access.log>
    WSGIScriptAlias / /var/www/html/projects/

Restart apache

$ sudo service httpd restart
Posted in Django | Tagged , , , , , , , , , , , , , | 2 Comments

Django Rest Framework with South solve for “cannot import name migrations”

Disclaimer: This isn’t a Django Rest Framework guide/tutorial post.

Today, I decided to give Django Rest Framework a go. Since this while I have been using Tastypie for developing APIs, and it has been pretty good with me. I like it because it is well documented and over time I have become quite familiar with the framework.

For my current project, I use Django 1.4 with South 0.7.6 for database migrations. I had to use Django Rest Framework 3.1.3 which is the last version that supports Django 1.4 and also it had support for TokenAuthentication which was required by my project.

Django versions < 1.7 used South for database migrations. Later on from Django 1.7, migrations were moved into Django project itself hence you do not need to use South anymore.

I installed DRF like so:

pip install djangorestframework==3.1.3

There are different authentication methods used to authenticate a client/user. I needed to use TokenAuthentication which verifies the client against a token/key which is stored on to the Database. To configure your project to be able to use TokenAuthentication, please refer the official documentation. You will need to add ‘rest_framework.authtoken’ under INSTALLED_APPS in

The token for each user is created under table authtoken_token in MySQL. To be able to migrate these changes you will need to run south migrations:

python schemamigration <app_name> --auto
python migrate <app_name>

However Django throws an error like so:

from django.db import models, migrations
ImportError: cannot import name migrations

This does not mean DRF version 3.1.3 does not support South. If you look inside /site-packages/rest_framework/authtoken/ there are 2 folders 1) Migrations 2) South Migrations. The error occurs because DRF assumes you are using Django’s builtin migrate command to make database migrations. We need to override this behaviour. To do this simply rename the “southmigrations” folder to “migrations” and do away with the original migrations folder. :)

I hope this solution worked for you, though I think the best thing to do would be to upgrade your Django version.

Posted in Django, Experience | Tagged , , , | Leave a comment

Attended Conf KDE India 2014

Last weekend I attended KDE India Conference at DAIICT, Gandhinagar. Thanks to Pradeepto for selecting my talk. It was quite exciting for me as it was not only my first KDE Conference but I was also delivering a talk there.


It was a thrilling experience to be around fellow open-source enthusiasts for a change. Thanks to the sponsors  Digia and VCreate Logic for making this event possible. Not to forget the awesome DAIICT organizers/volunteers Yash, Yashwant, Suchit and Shaleen for being so hospitable.

The event kicked of by a Qt Workshop carried out by Prashant Udupa. The students started asking many questions to speakers on the first day itself which showed how enthusiastic they were to learn Qt and were willing to contribute to KDE.


The following two days had many interesting talks. Jos spoke about KDE’s history and about its future which was quite interesting as most of the students were new to KDE. Kévin Ottens gave an awesome talk on C++11 which was very educative for the students who already had a working knowledge of C++. 

Thanks to fellow speakers Sinny, Samikshan, Chandan, Shubham […so many to name :D ] for making me feel so comfortable at my first KDE conf. I enjoyed speaking on such a huge platform…

Here is the traditional KDE Conf style group photo from the event…

Photo Credits - Sayantan Datta

Photo Credits – Sayantan Datta

PS: You can find my talk slides at:

Posted in KDE, Open Source, Qt, Qt Quick | Tagged , , , , | Leave a comment

Speaking at KDE Conf India 2014

Another huge KDE Meetup is on its way. From 21st February to 23rd February is going to organize a huge event at Gandhinagar and I will be giving a talk on “Writing Reusable QML components”. Here is the official page of the event.

A little birdie tells me there are a lot of open source enthusiasts attending the event who would like to take a plunge into Qt and KDE. And of course I’ve heard about the huge Nokia fan base at DAIICT. Please see me at the event, I’d love to meet fellow Nokia fans. Regarding my talk, I would give you a little ( but not so little) idea about writing custom QML components and of course how to make them reusable in terms of both design and functionality.  The talk has been marked as intermediate, although I suppose anyone who’d want to start on QML could attend this talk as I would be giving a basic introduction to QML to start with.

The talks are really interesting this time. You’d get to know where KDE is and where is it going from Jos Poortvliet and if you’d like to know about the very interesting Plasma Media Center you can attend Sinny Kumari’s talk. From Siteshwar and Shantanu you’ll learn about the Mer Project – powering Jolla Sailfish OS and Plasma Active (I am excited about this one!).

You can find list of all the talks here.

If you haven’t registered for the event and would like to, follow the registration link below.

See you at the event!

Posted in KDE, Open Source, Qt | Tagged , , , , , | Leave a comment

Movie Reviews Series 40 Web App

I have been working on a mobile application for Nokia Series 40 phones. This app is a Web App and is called Movie Reviews.

Movie Reviews is a Series 40 Web app which features latest movies, shows details (release date, cast, synopsis) and reviews for the selected movies, and also allows users to search for other movies from the Rotten Tomatoes movie database.

The Rotten Tomatoes API gives access to wealth of movie information, allowing anyone to build applications and widgets enriched with Rotten Tomatoes data. The API allows to get the current box office movies, new releases, upcoming movies and search for movies and retrieve detailed movie information, like cast, directors, and movie posters.

Here are some of the screenshots of the app,

Tab1   Movie Detail Page1     Movie Reviews Page

I wrote up an article on the Nokia Developer Wiki, explaining how it is developed. Check it out here. The project is an open source project available at Nokia Developer Projects.

Edit: As Nokia Developer Projects has now moved to Github, you can download the source code of Movie Reviews from the article page or directly by clicking here.

Posted in Code Example, Nokia, Open Source, Projects, Series 40 | Tagged , , | Leave a comment

Exploring my brand new Raspberry Pi

Recently, I was lucky enough to get one of those low cost $35 Raspberry Pi boards. Thanks to the Raspberry Pi Foundation and Nokia for initiating the Qt on Pi Program and distributing the boards among developers. It took quite some time for them to ship the board to me but finally it is here and it looks like this,

Avnee's Raspberry Pi

The board came with a 4 GB SD card and a Nokia USB charger.

Here’s what I did to get started with my Raspberry Pi:
– Downloaded the Raspian(the Raspberry Pi OS) and unzipped the file using Win32DiskImager.
– Got the Raspbian .img file written on to the SD cardWrite OS to SD Card

– Once done, inserted the SD card into the Raspberry Pi
– Connected the unit with my TV by plugging in the RCA composite (yellow-to-yellow RCA cable) into the RCA video slot
– Attached mouse to the USB port
– Finally, powered the board with a Nokia USB charger

Raspberry Pi in action
– Configured the rasp pi (guidelines to this are available easily)

And aha! My Television was now showing me the awesomeness of Raspberry Pi. So, that’s it for now, much more to be done yet with this tiny chip!

Check out some of the images of the board in action:

TV connected with Raspberry Pi

Slide Puzzle

Wormy - Game

Posted in Nokia, Projects | Tagged | Leave a comment

Concluding GSoC 2012

As mentioned previously, my proposal of “Porting KDiamond(game) to Qt Quick” had been selected for Google Summer of Code (GSoC), 2012. And now the project time has almost come
to an end. KDiamond has been ported to QtQuick successfully. Of course, there’s some optimization work that I plan to do after GSoC as well. Here is the git repository where I
pushed all my code:

This was my first GSoC experience and thus I got a lot of exposure to the KDE development environment. It was a great experience – The open environment in the company of really experienced developers, dealing with a lot of code and over an above being a part of a BIG community of developers. I had the pleasure to work under the guidance of really fantastic mentors,

  •  Ian Wadham for helping me set up the KDE development environment to begin with and later was really kind to give me honest pointers in my work
  •  David Edmundson for his expert advice about my project, coding style, etc.

Here are some of the screenshots from the KDiamond – QtQuick version of the game:

KDiamond - QtQucikVersion

Posted in Game, GSoC, KDE, Open Source, Projects, Qt Quick | Tagged , , , , , | Leave a comment