Creating a Virtual Development Server for Django projects: Part 2

This is the second part of our tutorial, check out Part 1 if you haven’t already!

If you, the reader, have some server admin-fu and have come to realize that you already know what you are doing, then feel free to either skip this part or consider the end of the post in the previous section. I, the author of said post, do not have any administration-fu and might be saying something professionally wrong here. Feel free to comment on my shortcomings.

Scripts and Arrangement of Files

Your home directory will be empty; I that recommend you create the “bin”, “sites”, and “envs” directories here.

  • ~/bin/
    • This folder will be automatically appended to the PATH by Ubuntu. It is so that you can call executable scripts as though you just installed them by apt-get install.
    • Of course, this will not take effect until your next restart with the VM
  • ~/sites/
    • This is where we will put all our shared folders
    • We just have to make sure that when mounting shared folders, the permissions of the mounted shared folder and its files are given to the current user
  • ~/envs/
    • This is where we will put all our per-project virtualenvs.
    • We have to put the virtualenvs inside the guest machine (obviously, right?) because that’s where we’ll be running Django’s development server. Sadly, we cannot put the env inside the project folder. Some errors about permissions happens when we create the virtualenv.

My Scripts and Stuff

Apparently, I am also the lazy type to do the same things repeatedly so I created 3 basic bash scripts. 2 independent scripts in case I need to call them independently and 1 script to call both (which is only used on startup). I am giving myself the liberty of posting here the scripts, in case you might want to copy them.

The startup script (filename: init-server):

scriptDir=`dirname $0`

The script for initializing the network interfaces (filename: Inuit-network):

ifconfig eth0 netmask up
 dhclient eth1

The script for remounting the shared folders (filename: init-vboxsfs):

declare -A vboxsfs
userId=`id -u vdev`
 # Format:
 # [vboxsf-name]=[mountdir-name]\
for vboxsf in ${!vboxsfs[@]}; do
umount $vboxsf
if [ ! -d “$sitesDir/$mountDir” ]; then
 mkdir “$sitesDir/$mountDir”
mount -t vboxsf -o uid=$userId,gid=$userId $vboxsf “$sitesDir/$mountDir”
echo “Mounted ‘$vboxsf’ vboxsf to $sitesDir/$mountDir”


I will be skipping the part where we mount the shared folders and create a virtualenv. Also, I would also like to assume that Django is already installed and your guest host-only network IP is

  • Edit your host machine’s /etc/hosts file. Add the ip entry with a custom domain name of your own. This can also be used for logging into your guest machine via SSH. There can be as many entries as you want. For now, let’s assume that your host entry is:
  • SSH into your guest machine
  • activate your project’s virtualenv
  • go to your project’s mounted directory and run: ./ runserver
  • On your host machine, open your browser and go to:
  • Voila!
  • This ends the post. I hope that you, the readers, found this useful.
Back to Blog