Skip to content

statetechnologies/dj-rest-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django API Simple Template

TOC

  1. Getting Started
  2. Setting up Postgres

Getting started

  • Create a new repository using this repo as a template
  • Create and Activate the virtual env
    python -m venv env && source env/bin/activate
  • Install the development dependencies
    pip install -r requirements/dev.txt
  • Configure Pre-commit (Optional)
    pre-commit install && pre-commit run --all-files
  • Setup localhost as the db host in settings.py

  • Cd into api folder

    cd api
  • Apply the migrations
    python manage.py migrate
  • Run the development server
    python manage.py runserver

Setting Up Postgres on Django Project

To set up PostgreSQL on a Linux system, you will need to do the following steps:

Install the PostgreSQL package:

sudo apt-get install postgresql postgresql-contrib

Start the PostgreSQL service:

sudo service postgresql start

Log in to the PostgreSQL command-line interface as the postgres user:

sudo -u postgres psql

Create a new database and user:

CREATE DATABASE mydatabase;

CREATE USER myuser WITH PASSWORD 'mypassword';

GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;

Note: Dont use the username user as it will conflict with the command

Exit the PostgreSQL command-line interface:

\q

Update the Django settings to use the new database:

# settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'mydatabase',
        'USER': 'myuser',
        'PASSWORD': 'mypassword',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

By following these steps, you should be able to set up PostgreSQL on your Linux system and use it with Django.

Releases

No releases published

Packages

No packages published

Languages