Skip to content

Instantly share code, notes, and snippets.

@wall-e-08
Last active August 17, 2019 19:26
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 wall-e-08/80c70191ddc06e6d74fd8f9de126bfa1 to your computer and use it in GitHub Desktop.
Save wall-e-08/80c70191ddc06e6d74fd8f9de126bfa1 to your computer and use it in GitHub Desktop.
One command install django(tested with django=2.2.4) with virtual_env, id, password and all apps in one project folder
#!/bin/bash
#--------------------------------------------
#---- Developer: Debashis Roy Bhowmik -------
#---- Email: debashis.buet08@gmail.com ------
#----------- Website: debashis.me -----------
#-- Github: https://github.com/wall-e-08/ ---
#--------------------------------------------
set -e # Exit immediately if a command exits with a non-zero status.
# create a variable to hold the input
read -p "Please enter project name: " project_name
if [[ -z "$project_name" ]]; then
echo "Insert project name";
return;
fi
mkdir "$project_name";
cd "$project_name";
virtualenv -p python3 env;
source env/bin/activate;
pip install Django==2.2.4;
django-admin startproject core;
mv core corebk;
mv corebk/* .;
rm -r corebk;
###########################################################################################################
# codes below are for inserting lines in a file into a given line number #
# this will work only for django version 2.1, because file's line numbers are counted and then inserted #
# if you want to use another version of django, please change code below #
###########################################################################################################
# static root in settings.py:
# $a\ for appending
sed -e '$a\STATIC_ROOT = os.path.join(BASE_DIR, "static")\n' -i core/settings.py;
sed -e '$a\try: from .local_settings import *;\nexcept ImportError: pass;\n' -i core/settings.py;
## inserting in lines are done here !!
touch core/local_settings.py;
echo "DEBUG=True" > core/local_settings.py;
pip freeze > requirements.txt;
python manage.py migrate;
python manage.py collectstatic --no-input;
echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', 'e@mail.com', 'a_very_lame_password');" | python manage.py shell;
echo "User Created: 'admin'"
python manage.py runserver 8000 || python manage.py runserver 8005; # try port 8000, if failed then try 8005
#--------------------------------------------
#---- Copyright: Debashis Roy Bhowmik -------
#---- Email: debashis.buet08@gmail.com ------
#----------- Website: debashis.me -----------
#-- Github: https://github.com/wall-e-08/ ---
#--------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment