Skip to content

Instantly share code, notes, and snippets.

@kidpixo
Forked from kalafut/django_init
Last active October 19, 2021 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kidpixo/fdf565d455652ddb33b29e232808ebb6 to your computer and use it in GitHub Desktop.
Save kidpixo/fdf565d455652ddb33b29e232808ebb6 to your computer and use it in GitHub Desktop.
Simple creation of a single-app django project
#!/bin/bash
#
# Simple creation of a single-app django project, as described in: https://zindilis.com/posts/django-anatomy-for-single-app/
#
# ./django_init foo
#
# This will result is the following flat structure:
#
# .
# └── foo
# ├── manage.py
# ├── settings.py
# ├── urls.py
# ├── foo
# │   ├── __init__.py
# │   ├── admin.py
# │   ├── apps.py
# │   ├── migrations
# │   │   └── __init__.py
# │   ├── models.py
# │   ├── tests.py
# │   └── views.py
# └── wsgi.py
#
# Note: this script assumes a GNU-compatible sed is installed. On macOS you can get this easily with Homebrew.
prj=$1
django-admin startproject $prj
cd $prj
mv $prj/* .
rm __init__.py
rm -rf $prj
sed -i 's/'"${prj}"'\.settings/settings/g' manage.py wsgi.py
sed -i 's/'"${prj}"'\.urls/urls/g' settings.py
sed -i 's/'"${prj}"'\.wsgi\.application/wsgi.application/g' settings.py
sed -i '/BASE_DIR = /s/Path(__file__).resolve().parent.parent/Path(__file__).resolve().parent/' settings.py
sed -i 's/'"${prj}"'\.wsgi\.application/wsgi.application/g' settings.py
./manage.py startapp ${prj}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment