The adorno.sh
script helps you to set up an environment for Django coding. Key advantages for this environment are:
- Code your files in a nice location on your main system as you would normally.
- Django and your code runs in a Virtual Machine (No installing packages such as different versions of python on your system=).
- Easy way to handle different python / django versions for different projects.
- Easy Version Controlling with Git!
- Etc Etc...
The environment that the Adorno script sets up consists of, in addition to the toolkit expected by Tango with Django, the following:
- VirtualBox (http://virtualbox.org/)
- Vagrant (http://www.vagrantup.com/)
- VirtualEnv Burrito, which includes:
- VirtualEnvWrapper (http://virtualenvwrapper.readthedocs.org/en/latest/install.html#quick-start)
- VirtualEnv
- PythonBrew
- Git
- Heroku (optional)
This README document also doubles as a quick-reference guide for beginners like me!
Note: All the command examples below contain the command prompt (everything before the $
). This shows you which terminal and which environment you should be in to execute the command properly. The command, incidentally, is everything after the $
, not including $
.
Note: the commands below given for the host are for a Debian-based (Ubuntu, LinuxMint, etc) computer. For Windows and Mac hosts, there might be small differences.
- Download and install VirtualBox from www.virtualbox.org. Use the packages from the website, not the ones in your distribution's repositories.
- Download and install Vagrant from www.vagrantup.com. Again, find the packages on the website.
- Download and install Git version control from www.git-scm.com.
host:~$ sudo apt-get -y install git
-
(Optional, Highly Recommended) Go to Heroku, create an account, and download and install the heroku toolkit www.heroku.com
-
Create a folder for your Django project.
host:~$ mkdir ~/tango
- Change to the project directory:
host:~$ cd ~/tango
- Download the Vagrantfile to your project directory:
host:~/tango$ wget https://raw.github.com/swiftarrow/Adorno/master/Vagrantfile
- Start Vagrant
host:~/tango$ vagrant up
- It will download and install the precise64 virtual image, and then boot the system. After booting, it will update the package lists, and then install
curl
. - After it's booted, log into the vagrant box by:
host:~/tango$ vagrant ssh
- At last, we can Add Adorno to your Tango with Django:
vagrant:~$ curl -s https://raw.github.com/swiftarrow/Adorno/master/adorno.sh | bash
- The Adorno script needs to run twice. The first run installs some dependencies and drops you back to the host. SSH back into vagrant and run the script again:
host:~/tango$ vagrant ssh
vagrant:~$ curl -s https://raw.github.com/swiftarrow/Adorno/master/adorno.sh | bash
-
Go over the output from the adorno command just to make sure that everything went through well.
If there were no errors, your good to go!
Adorno drops you into the foldervagrant:/vagrant/
, which is actually the same as your project directory,host:~/tango
-
Now it's time to start a virtual environment for our project:
vagrant:/vagrant$ mkvirtualenv tangodjango
- Continue with the Tango with Django instructions found here: http://www.tangowithdjango.com/book/chapters/requirements.html
- Install Django (section 2.2.4):
(tangodjango)vagrant:/vagrant$ pip install -U Django==1.5.4
- Install the Python Imaging Library (section 2.2.5):
(tangodjango)vagrant:/vagrant$ pip install pil
- Install other Python Packages that you need (section 2.2.6):
(tangodjango)vagrant:/vagrant$ pip install package_name
- Finally, save your Package List. Note: You should repeat this step again if you install any additional packages via pip.
(tangodjango)vagrant:/vagrant$ pip freeze > requirements.txt
Celebrate! You have finished setting up the requirements for Tango with Django! You can continue to follow the tutorial from section 3: http://www.tangowithdjango.com/book/chapters/setup.html
Since that's quite a bit of work for today, we'll finish up before starting the actual django project.
- First exit the vagrant box:
(tangodjango)vagrant:/vagrant$ exit
- Suspend the vagrant box:
host:~/tango$ vagrant suspend
- First de-activate the virtual environment:
(tangodjango)vagrant:/vagrant$ deactivate
- Exit the vagrant box:
vagrant:/vagrant$ exit
- Shut down the vagrant box:
host:~/tango$ halt
*Note: this is a sample workflow, assuming that you are on a nix based host computer. For windows based computers, the exact commands may vary slightly.
The best way to do this is have three terminal windows, each open to ~/tango
. On two of them, log into the vagrant box. Use one of these for runserver, and the other for file operations. Use the third window for file operations on the host system. For the following, we're labelling these three windows T1, T2, and T3.
- T1 Start the vagrant box that we've already prepared:
host:~/tango$ vagrant up
- T1 & T2 Log into the vagrant box:
host:~/tango$ vagrant ssh
- T1 & T2 Go to your project directory:
vagrant:~$ cd /vagrant
- T1 & T2 Enter the virtual environment:
vagrant:/vagrant$ workon tangodjango
- T1 If you haven't already, start a Django project:
(tangodjango)vagrant:/vagrant$ django-admin.py startproject rango-project
- T1 & T2 Enter the project directory:
(tangodjango)vagrant:/vagrant$ cd rango-project
Now you're all set. Use your editor on your host machine to edit the files as you need.
They are in the folder ~/tango/rango-project
Start django apps as necessary. Make or delete files as you need.
- T1 Finally, come to the live test (note the IP and port specifier are important!)
(tangodjango)vagrant:/vagrant/rango-project$ python manage.py runserver 0.0.0.0:8888
- On your host machine, open a browser and go to 127.0.0.1:8888 to admire your project!
Note: Heroku is a pretty awesome service, which allows us to run our apps live online, for free! To use it, we use Git to push our code to Heroku. All of these commands are done on the host machine (in the third terminal window, if you followed the Dance Steps above).
- Setup Heroku:
host:~/tango$ heroku login
Follow the instructions, generate an SSH key if necessary.
I recommend that you follow the first two lessons of Getting Started With Django to learn how to set your code up to deploy to Heroku and run locally at the same time. Alternatively, you can use the instructions at https://devcenter.heroku.com/articles/getting-started-with-django to set up your Django program for Heroku.
- Setup Git:
host:~/tango$ git init
- Add the files to Git:
host:~/tango$ git add .
- Commit the first version to Git:
host:~/tango$ git commit -am "The first Commit!"
1. Create a Heroku instance:
```bash
host:~/tango$ heroku create
- Deploy to Heroku:
host:~/tango$ git push heroku master
- The last command will give you a URL where you can see your code running live! Check it out:
host:~/tango$ heroku open
- Open a file, make some changes, save it.
- Check that Git has it marked for inclusion:
host:~/tango$ git status
- Add files as necessary (see Git documentation for help).
- Finally, commit all the necessary changes and write a short Commit Message:
host:~/tango$ git commit -am "Commit Message"
- Run your webapp on your own system as above, or on Heroku:
host:~/tango$ git push heroku master
host:~/tango$ heroku open
For added credit, create your own repository on GitHub and push your code to that!