Create Django Project with scaffolding from Django Cookiecutter

I use Django Cookiecutter (link) 🍪 because its awesome!

Find your python version

Hit the github page to see what python version it supports, you should match whichever provider support you have.

  • Django Cookiecutter: https://github.com/cookiecutter/cookiecutter-django (github)
  • Heroku supported python versions: (heroku)
Django Cookiecutter Github
Heroku

Create project: use pyenv to set python version

$ pyenv versions # check local installed python dists
$ pyenv install --list | grep 3.11 # shows all available 3.11 dists
$ pyenv install 3.11.3 # install python dist
$ PYENV_VERSION=3.11.3 python --version # check version
$ PYENV_VERSION=3.11.3 pip install "cookiecutter>=1.7.0" # install cookiecutter

$ PYENV_VERSION=3.11.3 cookiecutter https://github.com/pydanny/cookiecutter-django # create project

$ cd <project_name> # navigate to project

Note: if your pyenv install –list is not listing the newest versions, you’ll need to update pyenv. This is how to update pyenv with brew: $ brew upgrade pyenv

Setup project

# Set the latest python version as the project version
$ echo "3.11.3" > .python-version

$ pyenv version
3.11.3 (set by your/path/.python-version)

# Create and activate virtual environment
$ python -m venv env
$ source env/bin/activate

# Note: (env) will be prefixed from now on

# $ cat requirements/local.txt
# $ cat requirements/base.txt
(env) $  pip install -r requirements/local.txt

$ git init

# OPTIONAL pre-commit hook
# this installs pre-commit for black formatting, etc
# Note: if pre-commit is not installed for your latest python version, 
# run this in a different terminal:
#     $ PYENV_VERSION=<latest_version> pip install pre-commit
# Read the config with: $ cat .pre-commit-config.yaml
# website: https://pre-commit.com/
$ pre-commit install

$ git add . 
$ git commit -m "initial commit: django cookiecutter"
# here you may go through some cycles of formatting issues

Create database and first migration

$ createdb <project_name>

$ python manage.py migrate

$ python manage.py createsuperuser

$ python manage.py runserver

Visit 127.0.0.1:8000/admin to check out your admin console!

DONE! 🏄‍♂️