Running a Django Development Environment with Vagrant

django

One tool I’ve come to appreciate recently is Vagrant. Vagrant allows you to run a portable, virtual, OS instance. This means that if you work on more than one machine you don’t have to worry about having the same environment set up on each one. The vagrant install mounts your local home directory in the vagrant instance too (if you install VBoxGuestAdditions  -hint: scp the iso to the Vagrant instance and install it from there, not on the real computer), so you able to use a local IDE install (e.g. Pycharm) as your editor while running the code on your vagrant instance.

Getting the development server to run for Django is straightforward. First, install Vagrant using their install advice. Then edit the VagrantFile you are using by uncommenting or adding the following lines:

config.vm.network :private_network, ip: “192.168.33.10”      # good default
config.vm.network :forwarded_port, guest: 80, host: 8080  # good default
config.vm.synced_folder “./host_dir/”, “/vagrant/mount/location” # if you’re automounting (you’ll need VBoxGuestAddtion installed)

Next:

  1. Log in to your vagrant instance (default user/password=vagrant/vagrant) .
  2. Install and create a virtualenv (optional – but usually a good idea).
  3. Install django and a database.
  4. Create a django app (it can be empty).
  5. Start the django dev server with python manage.py runserver 192.168.33.10:8080 (given you used the above settings)
  6. Point your browser at http://192.168.33.10:8080/ .

If everything went well you should see a Django “It Worked!” screen.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s