- Pick box from Vagrant
- I chose ubuntu/xenial64
- create new folder, I called mine
djangoTut
- I added the path to djangoTut as an alias called djangoTut by:
- nano .bash_profile
- add the line: `alias djangoTut='cd "/Users/PATH_TO_YOUR_DJANGOTUT_FOLDER"'
- navigate to new folder in terminal
vagrant init ubuntu/xenial64
- edit vagrant file
- uncomment
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
- change ports
80
and8080
to8000
as that's what the django development server uses - so you now have
config.vm.network "forwarded_port", guest: 8000, host: 8000, host_ip: "127.0.0.1
- uncomment
vagrant reload
to load the new vagrant filevagrant ssh
to SSH into your new box
- create new folder, I called mine
python3 -m django --version
to confirm no django installed (or check version)- install database, if not SQLite, but tutorial uses SQLite
- remove django if you have an out of date version
- install pip
sudo apt-get update --fix-missing
(I did this at pip's instruction but assume I should have done it first)sudo apt install python3-pip
to install pippip3 install --upgrade pip
to upgrade pip
- setup virtualenv
pip3 install virtualenv
to install virtualenvcd /vagrant
virtualenv ENV
to create a new virtual environment in directory ENVsource ENV/bin/activate
to activate virtual env
pip install Django
to install Djangopython -m django --version
to check installed version - I have 1.11.3
django-admin startproject mysite
to create django settings, database configuration & file structure- check project working
cd /vagrant/mysite
python manage.py runserver 0.0.0.0:8000
to run lightweight non-production development server - here's why 0.0.0.0.:8000
- ctrl-c to exit server
cd /vagrant/mysite
to get to folder with manage.pypython manage.py startapp polls
to create polls app starter
- edit polls/views.py to: `from django.http import HttpResponse
def index(request): return HttpResponse("Hello, world. You're at the polls index.")`
- add new polls/urls.py with content: `from django.conf.urls import url
from . import views
urlpatterns = [ url(r'^$', views.index, name='index'), ]`
- add url pattern
url(r'^polls/', include('polls.urls')),
andfrom django.conf.urls import include
to mysite/urls.py
- in terminal
djangoTut
or navigate to the folder with your vm vagrant up
vagrant ssh
cd /vagrant/mysite
source ../ENV/bin/activate
python manage.py runserver 0:8000