Adding django via pipenv

Pip environments with python and django have evolved over the years, but once constant has remained: virtual environments to run the code and packages in. The latest consensus is to use pipenv to keep things separated. Let’s see how.

First, I’ll assume that you already have python 3.7 installed. If you need help, check out this other post I wrote: https://markcerv.com/2019/03/adding-python-3-7-to-ubuntu-18-x/

Next:

sudo apt install python-pip
sudo pip install pipenv

pipenv --python 3.7 install django

In order to use pipenv, you will need to cd to the directory where you want to put your code, and then:

cd  somename
pipenv --python 3.7 install django django-cors-headers \
         djangorestframework pytz
# a bunch of things will happen, including that a virtualenv
# will get get created like:
# ~/.local/share/virtualenvs/somename-oYSXMPkF

# to actually fire up the environment
pipenv shell

Next, you’ll need to setup a minimum of files to get django going. :

django-admin startproject test2

cd test2

python manage.py migrate     #will setup the needed database stuff
python manage.py createsuperuser    # lets you make a u/p for login

./manage.py  runserver  0.0.0.0:8000

You can now jump over to a browser, and visit http://127.0.0.1:8000/admin/ and sign in to your app. It’s pretty boring right now, but you can fix that.