Giter Site home page Giter Site logo

django_setup's Introduction

Django Projects - Setup Reference

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

Project Setup

  1. Make sure Postgres is running local
  2. Start project in PC
  3. Attach initial application for USERS
  4. Activate virtual environment:
venv/Scripts/activate
  1. Install required packages
pip install psycopg2-binary graphene-django python-dotenv
  1. Settings.py file should have the following imports
  from pathlib import Path
  from dotenv import load_dotenv
  import os
  load_dotenv()
  1. Make sure to add apps to INSTALLED_APPS in settings.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
  ]
  1. 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')
  ]
  1. Setup graphene schema in settings.py
  # Graphene settings
  GRAPHENE = {
    'SCHEMA': 'chat.schema.schema'
  }

Railway Deployments

  1. 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
    }
  }
  1. 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"],
    }
  }
  1. Add env variable to deployment. Setup postgres in project and reference direcly using rw's link service.

django_setup's People

Contributors

jiwallin3 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.