Created
August 25, 2021 05:20
-
-
Save omganeshdahale/fa1d0997ab7da4a63946b770000491c9 to your computer and use it in GitHub Desktop.
Bash script to start django project
This file contains 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
#!/bin/bash | |
EMAIL_USER="" | |
EMAIL_PASS="" | |
read -p "enter project name: " project_name | |
mkdir "$1/$project_name" | |
cd "$1/$project_name" | |
git init | |
cat > .gitignore << EOL | |
**/__pycache__/ | |
.venv/ | |
.env | |
db.sqlite3 | |
db.sqlite3-journal | |
EOL | |
python3 -m venv .venv | |
source .venv/bin/activate | |
pip install django | |
pip install python-dotenv | |
pip freeze > requirements.txt | |
django-admin startproject myproject . | |
cat > .env << EOL | |
$(grep "SECRET_KEY = " myproject/settings.py) | |
DEBUG = 'True' | |
EMAIL_USER = '$EMAIL_USER' | |
EMAIL_PASS = '$EMAIL_PASS' | |
EOL | |
sed -i "/from pathlib import Path/i import os\nfrom django.contrib.messages import constants as messages\nfrom dotenv import load_dotenv" myproject/settings.py | |
sed -i "/BASE_DIR = /a load_dotenv(BASE_DIR / '.env')" myproject/settings.py | |
sed -i "s/SECRET_KEY = .*/SECRET_KEY = os.getenv('SECRET_KEY')/" myproject/settings.py | |
sed -i "s/DEBUG = .*/DEBUG = os.getenv('DEBUG') == 'True'/" myproject/settings.py | |
sed -i "s/'DIRS': \[\]/'DIRS': \[BASE_DIR \/ 'templates'\]/" myproject/settings.py | |
echo " | |
MESSAGE_TAGS = { | |
messages.DEBUG: 'secondary', | |
messages.ERROR: 'danger', | |
} | |
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' | |
EMAIL_HOST = 'smtp.gmail.com' | |
EMAIL_PORT = 587 | |
EMAIL_USE_TLS = True | |
EMAIL_HOST_USER = os.environ.get('EMAIL_USER') | |
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASS')" >> myproject/settings.py | |
mkdir templates | |
touch templates/base.html | |
echo done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment