Last active
April 6, 2018 17:46
-
-
Save codyeatworld/eef63d2d2712045faf5149cddcb37b9e to your computer and use it in GitHub Desktop.
Generate django projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# djgen <project_name> <app_name> | |
# Parameters: | |
# $1 <project_name> | |
# $2 <app_name> | |
djgen() { | |
echo "π [Running] django-admin startproject $1" | |
django-admin startproject $1 | |
cd $1 | |
echo "π [Running] mkdir apps" | |
mkdir apps | |
echo "π [Running] touch apps/__init__.py" | |
touch apps/__init__.py | |
cd apps | |
echo "π [Running] python ../manage.py startapp $2." | |
python ../manage.py startapp $2 | |
cd ../ | |
echo "π [Running] mkdir -p apps/$2/templates/$2" | |
mkdir -p apps/$2/templates/$2 | |
echo "π [Running] touch apps/$2/templates/$2/index.html" | |
touch apps/$2/templates/$2/index.html | |
echo "β¨ [Generating] apps/$2/templates/$2/index.html" | |
echo "<h1>Hi</h1>" >> apps/$2/templates/$2/index.html | |
echo "β¨ [Generating] apps/$2/urls.py" | |
touch apps/$2/urls.py | |
echo "from django.conf.urls import url" >> apps/$2/urls.py | |
echo "from . import views" >> apps/$2/urls.py | |
echo "" >> apps/$2/urls.py | |
echo "urlpatterns = [" >> apps/$2/urls.py | |
echo " url(r'^', views.index)," >> apps/$2/urls.py | |
echo "]" >> apps/$2/urls.py | |
cd $1 | |
echo "βοΈ [Modifying] $1/urls.py" | |
gsed -i '16s/$/, include/' urls.py | |
gsed -i "20i\ url(r'^', include('apps.$2.urls'))," urls.py | |
echo "βοΈ [Modifying] $1/settings.py" | |
gsed -i "34i\ 'apps.$2'," settings.py | |
cd ../ | |
echo "βοΈ [Modifying] apps/$2/views.py" | |
echo "def index(req):" >> apps/$2/views.py | |
echo " return render(req, '$2/index.html')" >> apps/$2/views.py | |
cd ../ | |
touch $1/apps/$2/views.py | |
touch $1/apps/$2/urls.py | |
touch $1/apps/$2/templates/$2/index.html | |
echo "" >> $1/$1/settings.py | |
touch $1/$1/urls.py | |
echo "π [Migrating] python manage.py migrate" | |
cd $1 | |
python manage.py migrate | |
cd ../ | |
echo "Done!" | |
} | |
# pyenv() { | |
# source ~/codingdojo/python/envs/$1/bin/activate | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment