Skip to content

Instantly share code, notes, and snippets.

@kalafut kalafut/django_init
Last active Dec 27, 2018

Embed
What would you like to do?
Simple creation of a single-app django project
#!/bin/bash
#
# Simple creation of a single-app django project, as described in: https://zindilis.com/blog/2017/01/06/django-anatomy-for-single-app.html
#
# ./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 's/os.path.dirname(os.path.dirname(os.path.abspath(__file__)))/os.path.dirname(os.path.abspath(__file__))/g' 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
You can’t perform that action at this time.