Skip to content

Instantly share code, notes, and snippets.

@wall-e-08
Last active August 17, 2019 19:25
Show Gist options
  • Save wall-e-08/5de1ed5d6bce76af60266208f107e159 to your computer and use it in GitHub Desktop.
Save wall-e-08/5de1ed5d6bce76af60266208f107e159 to your computer and use it in GitHub Desktop.
one command to install django(tested with django=2.1.3) 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.1.3;
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:
sed -e '120iSTATIC_ROOT = os.path.join(BASE_DIR, "static")\n' -i core/settings.py;
sed -e '123itry: 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;
#--------------------------------------------
#---- 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