Update backend/README.md
updated readme formatting
This commit is contained in:
parent
99c84b9572
commit
5ce795ce14
@ -4,81 +4,109 @@
|
|||||||
*** DJANGO ENVIRONMENT LOCAL SETUP (installing libraries/dependencies) ***
|
*** DJANGO ENVIRONMENT LOCAL SETUP (installing libraries/dependencies) ***
|
||||||
|
|
||||||
|
|
||||||
- install ffmpeg for audio file processing on your system:
|
- install ffmpeg for audio file processing on your system (ubuntu):
|
||||||
|
```
|
||||||
sudo apt-get install net-tools
|
sudo apt-get install net-tools
|
||||||
sudo apt install ffmpeg
|
sudo apt install ffmpeg
|
||||||
|
```
|
||||||
|
|
||||||
- install postgres
|
- install postgres
|
||||||
|
```
|
||||||
sudo apt install libpq-dev
|
sudo apt install libpq-dev
|
||||||
sudo apt install postgresql
|
sudo apt install postgresql
|
||||||
sudo apt install postgresql-contrib
|
sudo apt install postgresql-contrib
|
||||||
|
```
|
||||||
|
|
||||||
- make sure python is installed (should come with ubuntu):
|
- make sure python is installed (should come with ubuntu):
|
||||||
python (or python3) --version
|
`python --version`
|
||||||
|
|
||||||
Django setup (Using Python -v 3.10.6 and Django -v 4.2 as of April, 29, 2023):
|
Django setup (Using Python -v 3.10.6 and Django -v 4.2 as of April, 29, 2023):
|
||||||
|
|
||||||
- make dir on local machine where this project will be located
|
- create dir on local machine where this project will be stored
|
||||||
|
`mkdir selah`
|
||||||
- clone this repo from github (ssh or https, see top level servers_ssl_db_setup digitalocean_server.txt)
|
|
||||||
|
|
||||||
- install python venv:
|
- install python venv:
|
||||||
sudo apt install python3.10-venv
|
`sudo apt install python3.10-venv`
|
||||||
|
|
||||||
- Create python virtual environment on local machine (shouldn't need to do this step if cloning from git, just install venv and try to activate the env in next step):
|
- Create python virtual environment on local machine:
|
||||||
|
`python3 -m venv env`
|
||||||
|
|
||||||
python3 -m venv env
|
- clone this repo via https or ssh in the directory you created above; your python env folder should be next to the repo, not within it
|
||||||
|
|
||||||
- Activate python virtual environment on local machine:
|
|
||||||
|
|
||||||
. env/bin/activate
|
|
||||||
(you'll see '(env)' on the left-most side the terminal signature when activated)
|
|
||||||
|
|
||||||
- Once your env is activated, install Django and other dependencies (see requirements.txt):
|
- Activate python virtual environment on local machine. You'll see '(env)' on the left-most side the terminal signature when activated
|
||||||
|
- Ubuntu:
|
||||||
|
`. env/bin/activate `
|
||||||
|
- windows:
|
||||||
|
``
|
||||||
|
|
||||||
pip install django (the backend framework)
|
- Once your env is activated, install Django and other dependencies (see requirements.txt or just copy/paste this in the terminal):
|
||||||
pip install django-rest-framework (creating the backend API, creates djangorestframework dir as well)
|
```
|
||||||
pip install djangorestframework-simplejwt (Simple JWT provides a JSON Web Token authentication backend for the Django REST Framework. Updated framework from djangorestframework-jwt which is now deprecated)
|
pip install django
|
||||||
pip install pyjwt (Python library which allows you to encode and decode JSON Web Tokens JWT)
|
pip install django-rest-framework
|
||||||
pip install social-auth-app-django (for 3rd party auth Facebook, Google, LinkedIn, etc.)
|
pip install djangorestframework-simplejwt
|
||||||
pip install django-cors-headers (provides security between backend and API)
|
pip install pyjwt
|
||||||
pip install djoser (assists with user auth)
|
pip install social-auth-app-django
|
||||||
pip install pillow (image processing)
|
pip install django-cors-headers
|
||||||
pip install django-imagekit (django image processing for track image)
|
pip install djoser
|
||||||
pip install pydub (audio file processing)
|
pip install pillow
|
||||||
pip install django-environ (for environment variables)
|
pip install django-imagekit
|
||||||
pip install stripe (payment processor for handling secure payments)
|
pip install pydub
|
||||||
pip3 install --upgrade stripe (upgrade stripe)
|
pip install django-environ
|
||||||
pip install psycopg2 (database adapter for PostgreSQL DB. Use this for local development, but in the production server, install the binary:
|
pip install stripe
|
||||||
pip install psycopg2-binary
|
pip3 install --upgrade stripe
|
||||||
)
|
pip install psycopg2
|
||||||
install pgadmin4 desktop tool for DB management (https://www.pgadmin.org/download/)
|
|
||||||
pip install gunicorn
|
pip install gunicorn
|
||||||
|
```
|
||||||
|
(For production server, install the binary:
|
||||||
|
|
||||||
|
`pip install psycopg2-binary`
|
||||||
|
)
|
||||||
|
|
||||||
|
- install pgadmin4 desktop GUI tool for DB management (https://www.pgadmin.org/download/):
|
||||||
|
|
||||||
|
|
||||||
*** Note: You need to create empty DB in either psql shell or pgadmin tool before running python manage.py makemigrations and python manage.py migrate (If you want to use custom user model, DO NOT RUN python manage.py makemigrations/migrate until you have created your custom user model, otherwise Django will revert to its default User Model. Changing from Django's default user model to a custom user model is possible, but unsupported and prone to many errors. Do this first before anything else if that's what you want for your app)
|
*** Note: You need to create empty DB in either psql shell or pgadmin tool before running python manage.py makemigrations and python manage.py migrate (If you want to use custom user model, DO NOT RUN python manage.py makemigrations/migrate until you have created your custom user model, otherwise Django will revert to its default User Model. Changing from Django's default user model to a custom user model is possible, but unsupported and prone to many errors. Do this first before anything else if that's what you want for your app)
|
||||||
|
|
||||||
- activate env
|
- make sure env is activated and start Django dev server:
|
||||||
(linux) . env/bin.activate
|
- in the `main_project` directory, create a new `.env` file with the following variables. Get values from me:
|
||||||
- create new Django project (make sure you are in dir you want project to be created):
|
```
|
||||||
django-admin startproject yourprojectname
|
DEV_MODE=
|
||||||
- start Django dev server:
|
DOMAIN=
|
||||||
|
DEV_DOMAIN=
|
||||||
|
FRONTEND_DOMAIN=
|
||||||
|
FRONTEND_DEV_DOMAIN=
|
||||||
|
EMAIL_HOST=
|
||||||
|
EMAIL_PORT=
|
||||||
|
EMAIL_HOST_USER=
|
||||||
|
EMAIL_HOST_PASSWORD=
|
||||||
|
SECRET_KEY=
|
||||||
|
DBENGINE=
|
||||||
|
DBNAME=
|
||||||
|
DBUSER=
|
||||||
|
DBPASSWORD=
|
||||||
|
DBHOST=
|
||||||
|
STRIPE_DOMAIN=
|
||||||
|
STRIPEPK=
|
||||||
|
STRIPESK=
|
||||||
|
STRIPE_WEBHOOK_SECRET=
|
||||||
|
SECURE_SSL_REDIRECT=
|
||||||
|
SESSION_COOKIE_SECURE=
|
||||||
|
CSRF_COOKIE_SECURE=
|
||||||
|
ADMIN_URL=
|
||||||
|
```
|
||||||
set backend env DEV_MODE var:
|
set backend env DEV_MODE var:
|
||||||
DEV_MODE=True
|
DEV_MODE=True
|
||||||
|
|
||||||
|
|
||||||
- start Django dev server in terminal:
|
- start Django dev server in terminal:
|
||||||
DJANGO_SETTINGS_MODULE=sheriff_crandy_project.dev_settings python manage.py runserver
|
DJANGO_SETTINGS_MODULE=main_project.dev_settings python manage.py runserver
|
||||||
|
|
||||||
|
|
||||||
- you should be able to access backend at
|
- you should be able to access backend at
|
||||||
127.0.0.1:8000
|
127.0.0.1:8000
|
||||||
|
|
||||||
- you can now create apps (for models --users, tracks, artists, etc; make sure you are in project root directory when creating apps. After creating an app, make sure you register it by adding it to the main project's settings.py file INSTALLED_APPS dict)
|
|
||||||
|
|
||||||
python manage.py startapp my_app_name
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
To run vs code debugger:
|
To run vs code debugger:
|
||||||
@ -107,24 +135,6 @@ In top level directory, add this launch.json file:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
In main_project folder, create .env file
|
|
||||||
add these env vars:
|
|
||||||
|
|
||||||
DOMAIN=https://sheriffcrandymusic.local:9443/api
|
|
||||||
DEV_DOMAIN=http://127.0.0.1:8000
|
|
||||||
DEV_MODE=True
|
|
||||||
|
|
||||||
Should be it. Activate your python env:
|
|
||||||
. env/bin/activate
|
|
||||||
And start Django's dev server with the dev settings:
|
|
||||||
|
|
||||||
start dev server using dev mode settings:
|
|
||||||
DJANGO_SETTINGS_MODULE=sheriff_crandy_project.dev_settings python manage.py runserver
|
|
||||||
|
|
||||||
|
|
||||||
Now go to an API endpoint and verify the dev site is being served:
|
|
||||||
http://127.0.0.1:8000/api/sc/v1/tracks/
|
|
||||||
|
|
||||||
|
|
||||||
If you were preveiously in production mode, stop all nginx and gunicorn servers and open
|
If you were preveiously in production mode, stop all nginx and gunicorn servers and open
|
||||||
your browser's dev tools and clear all cache and cookie data:
|
your browser's dev tools and clear all cache and cookie data:
|
||||||
|
Loading…
Reference in New Issue
Block a user