Standard django project setup information. This is a living document and will change with my preference. It is intended for my reference but made public in case it can help others. I use PyCharm Pro (PC) as my ide. I appreciate the features they have built in and the template project starts
- Make sure Postgres is running local
- Start project in PC
- Attach initial application for
USERS
- Activate virtual environment:
venv/Scripts/activate
- Install required packages
pip install psycopg2-binary graphene-django python-dotenv
- Settings.py file should have the following imports
from pathlib import Path
from dotenv import load_dotenv
import os
load_dotenv()
- Make sure to add apps to
INSTALLED_APPS
insettings.py
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
'graphene_django', # add graphene_django to INSTALLED_APPS
'threejuliet.apps.ThreeJulietConfig', # add threejuliet config app to INSTALLED_APPS
'chat.apps.ChatConfig', # add chat app to INSTALLED_APPS
]
- Setup static files in
settings.py
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = "/static/"
# Set the STATIC_ROOT setting to a valid filesystem path where Django can collect static files
STATIC_ROOT = os.path.join(BASE_DIR, 'collected_static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/media')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
- Setup graphene schema in
settings.py
# Graphene settings
GRAPHENE = {
'SCHEMA': 'chat.schema.schema'
}
- Include a railway.json file in your root directory. The format given by Railway is:
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "python manage.py migrate && python manage.py collectstatic --noinput && gunicorn threejulietai.wsgi",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
- Railway db setup for postgres
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ["PGDATABASE"],
'USER': os.environ["PGUSER"],
'PASSWORD': os.environ["PGPASSWORD"],
'HOST': os.environ["PGHOST"],
'PORT': os.environ["PGPORT"],
'URL': os.environ["DATABASE_URL"],
}
}
- Add env variable to deployment. Setup postgres in project and reference direcly using rw's link service.