Django + Raspberry Pi Tutorial (PART I)

UPDATE (1/11/2017): The new tutorial can be found at: http://raspberrypituts.com/raspberry-pi-django-tutorial-2017/

This tutorial will walk you through how to setup your Raspberry Pi with Django. If you have any problems setting up the Django + Raspberry Pi Tutorial (PART I) setup be sure to comment questions or suggestions, be sure to post them at the bottom of the page. If you’d like to become a contributor or edit for the Django + Raspberry Pi Tutorial (PART I) please feel free to contact me.

Start: Django + Raspberry Pi Tutorial (PART I)

Step 1. Updating and Cleaning your Raspberry Pi

Step 2. Install Python MySQLDB

Step 3. Install LAMP Server

The second install on this step will ask you to create a password for the root SQL user.

Step 4. Install PHPMyAdmin and configure it to Apache.

This step will ask you which server you would like to use for your application. I chose Apache.

In this you’ll see include statements, find an empty line right after the include conf.d/ that has an empty line after it. Go down until are on the empty line. Type the following:
Restart the server to be able to access phpmyadmin on your local server (in a browser go to localhost/phpmyadmin).

Step 5. Install Python Setup tools

Step 6. Make sure you have PIP installed

Step 7: Install Django

Step 8: Creating our application

I will use the name DjangoProject but you can call yours whatever you prefer.

Step 9: Migrating DB and Running App

Migrate the DB and starting our application. Use your Raspberry Pi IP address (mine is 192.168.0.5) and choose what port you’d like to run on.

You can then head to 192.168.0.5:8000 from your computer and you should see this if everything worked properly.

RaspberryPiDjangoWebApp

Step 10: Customize our App

Check out the next tutorial.

You may also like...

10 Responses

  1. chris says:

    this is nice tut however i still dont understand how this makes use of the apache server we installed? its still using the django devopment server.?

  2. chris: I agree. The Apache2 server actually causes problems with the standard HTTP port 80 for the Django app, since Apache2 occupy that port. If you want your Django app to use the normal HTTP port 80 you have to stop apache2 and make sure it does not start at boot.

    Stop apache2 service: sudo service apache2 stop
    Stop apache2 from starting at boot, in /etc/init.d/: sudo chmod -x apache2

    After this you can start your Django server with: python manage.py runserver MySite.com:80
    Make a shell script (AnyNameIsFine.sh) in /etc/init.d/ holding the above command and “sudo chmod +x AnyNameIsFine.sh” to start your Django site at boot.

  3. Just note that as of 11/19/2016 the updated location for get-pip.py is https://bootstrap.pypa.io/get-pip.py

    Hence step 6 should be changed to: wget https://bootstrap.pypa.io/get-pip.py

    Hope that helped 🙂

  4. Cancelor says:

    I found that on step 9 I had to use python3 instead of just python to run those two lines.

    Also, when I smurfed to 192.168.1.4:8000 or even localhost:8000 I got a different screen that states :- “You may need to add ‘192.168.1.4’ to ALLOWED_HOSTS”

    • aaron says:

      I think I am having a similar issue. When I try to navigate to the sample page through my browser I get an error message saying ‘DisallowedHost at /’, then there is a bunch of stuff I do not understand.

      When I tried your suggestion of using python3 I also get an error saying that there is no Django module installed.

      Any ideas? (I am a little over my head with some of this stuff, just a beginner to linux and python/django).

  5. Amirul says:

    Go to setting.py add your ip or or your domain under ALLOWED_HOSTS = []
    Like this :
    ALLOWED_HOSTS = [ ‘192.168.1.2 ‘ ] # for internal ip
    ALLOWED_HOSTS = [ ‘www.yourdomain.com’ ]# for domain name install

  1. May 19, 2015

    […] This tutorial will walk you through how to setup your first Django Web Application. It is based off of the work done in the previous tutorial. […]

Leave a Reply

Your email address will not be published. Required fields are marked *