Set up a virtual Django development environment for Python applications. Create this with Vagrant, Ubuntu, and Virtualbox.

Inside the command line/Terminal:

Start a django app

              django-admin startproject YOURPROJECTTITLEHERE

Then change directory into your project file


Initialize a vagrantfile

vagrant init techbytes/djangoubuntu

Configure our Vagrantfile

Forwarded port

 Uncomment out the forwarded port code by removing the # from “forwarded_port”, guest: 80, host: 8080

Private network

Uncomment out the private network and change the IP address to “”

Because the django server is configured to only work on your computer or the localhost

In this case we are a guest connecting to virtual host machine

So we need to set up a private network — in this case we will use

Then we need to add this to our file as an Allowed Host

Stand up our Vagrant box

vagrant up

Change directory into our /vagrant folder

Perform any migrations that may be necessary

python3 migrate

Run the server

python3 runserver

Go to your browser and type in and view your success message

If this is your first time building a Django app add /admin to your url and get a little more impressive portion of the built in admin functionality of django

To review all this you will need to create a superuser and password — and I will leave that to you

Now what would happen if we did not add the ip address to the Allowed Hosts — let’s see —

Go back to the and remove the string, save and then reload your browser

The python app still comes up, but with an invalid host message — luckily the message is rather verbose and tells you what you need to do — add ‘’ to the Allowed Hosts

So let’s pop that back in and see it working again

Now once you are done working in your virtual environment you will want o bring down your virtual machine — exit out of the vagrant ssh, and vagrant destroy, suspend, or halt your machine — I am going to vagrant destroy


VIDEO: Virtual Django Environment with Vagrant

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s