Coder Social home page Coder Social logo

django-setup-wiki's Introduction

Django Setup Wiki

Instructions for setting up Django projects.

Table of Contents

  1. General Setup for all Django Projects
  2. Django REST Framework
  3. Django GraphQL
  4. Django MongoDB
  5. Full-Stack Django (with templates)

General Setup for all Django Projects

Recommended Technologies

  • Django 3.x
  • Poetry
  • Postgres: You can use MySQL or SQL Lite, but Postgres is recommended by the Django official docs. The only exception is if you want to use MongoDB or another NoSQL database with your project. You can find details for that below.

Initial Setup

  1. Must have Python 3, Django, and Postgres version 12.x installed

  2. Make sure Postgres is running on your machine

  3. django-admin startproject [projectname]

  4. Create a virtual environment: python -m venv venv

  5. Go into your virtual environment: source venv/bin/activate

  6. Run poetry init -> This will create a TOML file for you with your project config where Poetry will add your dependencies

  7. Install psycopg2-binary: poetry add psycopg2

  8. Rename the [projectname] folder to config

  9. Create a folder named apps

  10. Create an __init__.py file inside of the apps folder

Users Setup

  1. Create a users app: mkdir apps/users and then python manage.py startapp users apps/users
  2. Setup custom User model and custom user manager: https://docs.djangoproject.com/en/3.1/topics/auth/customizing/#a-full-example
AUTH_USER_MODEL = 'users.User'
  1. Set up admin interface for User model:
from django.contrib import admin
from .models import User


class UserAdmin(admin.ModelAdmin):
    list_display = ('email', 'is_admin')


admin.site.register(User, UserAdmin

Database Setup

Postgres is optional, but recommended in the official Django docs.

  1. Setup Postgres in Django settings.py file:
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': '[dbname]',
    'USER': '[dbadmin]',
    'PASSWORD': '',
    'HOST': 'localhost',
    'PORT': '',
}
  1. Setup Database in Postgres
    1. Create the database: CREATE DATABASE [dbname];
    2. Create DB user: `CREATE USER [dbadmin];
    3. Grant privilages to user for our database: GRANT ALL PRIVILEGES ON DATABASE coducat TO [dbadmin];
    4. Run migrations: python manage.py migrate

More Setup

  1. Create an admin user for logging into the Django admin interface: python manage.py createsuperuser
  2. Run the app: python manage.py runserver
  3. View the API at localhost:8000 and the admin interface at localhost:8000/admin

Django REST Framework

This builds off of the general Django setup steps.

Technologies

  • Django REST Framework

REST Framework Setup

  1. Install the REST Framework with Poetry: poetry add djangorestframework
  2. Set up Django REST Framework
    1. Add DRF to INSTALLED_APPS: 'rest_framework'
    2. Add DRF URLs to urlpatterns: path('', include('rest_framework.urls')),
  3. You can run the Django app normally: python manage.py runserver
  4. Now go to localhost:8000 in your browser and you should see Django REST frameworks default page showing you all the routes you have available to you.

Apps Setup

  1. Create apps
  2. Create Models
  3. Setup Admin interface
  4. Create urls.py file
  5. Setup URLs
  6. Setup Views

Optional Setup

  1. Setup token auth
  2. Setup nested routes: rest_framework_nested
  3. Pagination
  4. Timestamp util for models

Django Graphql

Technologies

Django MongoDB

Technologies

  • MongoDB (Running locally)
  • Djongo

Full-Stack Django

coming soon...

django-setup-wiki's People

Contributors

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