STEP 1: INITIATING PROJECT
-
virtualenv env
-
env\Scripts\activate
-
pip install -r requirements.txt with following requirements asgiref==3.5.2 Django==4.1.3 sqlparse==0.4.3 tzdata==2022.6 gunicorn==20.1.0 psycopg2==2.9.3 dj-database-url==0.5.0
-
django-admin startproject codingmstrproject
-
python manage.py startapp codingmstrapp
-
python manage.py runserver
-
Create a frontend folder
-
cd frontend
-
npx create-react-app ./
-
Go to Django path
STEP 2: SETTING DJANGO
-
TEMPLATES
'DIRS': [ os.path.join(BASE_DIR, 'frontend/build') ], -
Add Inside urls.py
from django.contrib import admin from django.urls import path, include, re_path from django.conf import settings from django.views.static import serve
urlpatterns = [ path('', include('attendance.urls')), path('admin/', admin.site.urls),
re_path(r'^media/(?P<path>.*)$', serve,{'document_root':settings.MEDIA_ROOT}),
re_path(r'^static/(?P<path>.*)$', serve,{'document_root':settings.STATIC_ROOT}),
]
-
Add Inside views.py def index(request): return render(request, 'index.html')
-
Make Other urls.py inside codingmstrapp directory and add these lines from django.urls import path from . import views from django.conf import settings from django.urls import path, include from django.conf.urls.static import static
urlpatterns = [ path('', views.index, name='index'), ]
- Add Inside Setting.py import os from urllib.parse import urlparse from django.core.management.utils import get_random_secret_key import sys import dj_database_url
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY", get_random_secret_key())
DEBUG = os.getenv("DEBUG", "False") == "True"
ALLOWED_HOSTS = os.getenv("DJANGO_ALLOWED_HOSTS", "127.0.0.1, localhost").split(",")
Add codingmstrapp in Installed Apps
DEVELOPMENT_MODE = os.getenv("DEVELOPMENT_MODE", "False") == "True"
if DEVELOPMENT_MODE is True: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'cdotdb', 'USER': 'postgres', 'PASSWORD': '1234', 'HOST': 'localhost', } } elif len(sys.argv) > 0 and sys.argv[1] != 'collectstatic': if os.getenv("DATABASE_URL", None) is None: raise Exception("DATABASE_URL environment variable not defined") DATABASES = { "default": dj_database_url.parse(os.environ.get("DATABASE_URL")), }
STATIC_URL = 'static/' STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'frontend/build/static'),
-
go to frontend by typing 'cd frontend' in cmd and
-
write command 'npm run build' to generate build file inside frontend
-
Create migrations by typing 'python manage.py makemigrations' and
-
then type 'python manage.py migrate'
-
Type 'python manage.py createsuperuser' and enter details like username, email and password
STEP 3: SETUP GIT ACCOUNT
-
git init
-
git remote add origin [email protected]:{name}/{name}
-
git branch -M branch
-
git add *
-
git commit -m 'first'
-
git push -u origin main
STEP 4: SET DIGITALOCEAN APP
20 Environment Variables
DJANGO_ALLOWED_HOSTS ${APP_DOMAIN}
DEBUG True
DJANGO_SECRET_KEY 94875uwegsdkjlg (Encrypted)
DEVELOPMENT_MODE False
- Add Run Command gunicorn --worker-tmp-dir /dev/shm codingmstrproject.wsgi