Skip to content

Augustus2011/djangoreact_testdeploy

 
 

Repository files navigation

STEP 1: INITIATING PROJECT

  1. virtualenv env

  2. env\Scripts\activate

  3. 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

  4. django-admin startproject codingmstrproject

  5. python manage.py startapp codingmstrapp

  6. python manage.py runserver

  7. Create a frontend folder

  8. cd frontend

  9. npx create-react-app ./

  10. Go to Django path

STEP 2: SETTING DJANGO

  1. TEMPLATES
    'DIRS': [ os.path.join(BASE_DIR, 'frontend/build') ],

  2. 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}), 

]

  1. Add Inside views.py def index(request): return render(request, 'index.html')

  2. 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'), ]

  1. 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

For Server

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")

Extra places for collectstatic to find static files.

STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'frontend/build/static'),

  1. go to frontend by typing 'cd frontend' in cmd and

  2. write command 'npm run build' to generate build file inside frontend

  3. Create migrations by typing 'python manage.py makemigrations' and

  4. then type 'python manage.py migrate'

  5. Type 'python manage.py createsuperuser' and enter details like username, email and password

STEP 3: SETUP GIT ACCOUNT

  1. git init

  2. git remote add origin [email protected]:{name}/{name}

  3. git branch -M branch

  4. git add *

  5. git commit -m 'first'

  6. 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

  1. Add Run Command gunicorn --worker-tmp-dir /dev/shm codingmstrproject.wsgi

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 51.7%
  • CSS 43.2%
  • Python 3.9%
  • HTML 1.2%