Giter Site home page Giter Site logo

backend's Introduction

#This is a sandbox for Elasticksearch, Django, Postgres and Reactjs

requirements
+ python3.5

STEP 1 create simple django project with postgres

let us create backend project

django-admin startproject backend

then create database and user with privileges, for this you can run script scripts/create-db.sh or connect to database management system and do it like I did in Postgres

psql
CREATE USER user171030 WITH PASSWORD 'user171030';
ALTER ROLE user171030 SET client_encoding TO 'utf8';
ALTER ROLE user171030 SET default_transaction_isolation TO 'read committed';
ALTER ROLE user171030 SET timezone TO 'UTC';
ALTER USER user171030 CREATEDB;


CREATE DATABASE user171030;
GRANT ALL PRIVILEGES ON DATABASE user171030 TO user171030;

and now write down connect to database in django app settings backend/backend/settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'user171030',
        'USER': 'user171030',
        'PASSWORD': 'user171030',
        'HOST': 'localhost',
        'PORT': '5432'
    }
}
cd backend
python manage.py migrate

let's check our backend is working!!!

python manage.py runserver

rememeber names of our packages in requirements.txt

pip freeze > requirements.txt

opposite command, load packages from requirements.txt

pip install -r requirements.txt

STEP 2 Setup JWT Auth for django project

cd backend

pip install coreapi djangorestframework \
      djangorestframework-simplejwt

change install apps in settings.py

INSTALLED_APPS = [
    ...
    'rest_framework',
]

# Rest Framework
REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    ),
}

now let us make some changes in urls.py (have a look in git repo)

Now start up server!

./manage.py runserver

4 STEP create test rest api SECURE and INSECURE

cd backend && ./manage.py startapp app_log

in file app_log/models.py create model

add app in backend/settings.py

INSTALLED_APPS = [
    ...
    'app_log',
]

TODO add description

Create User Settings App

mkdir -p apps/user_settings
./manage.py startapp user_settings apps/user_settings

loading initial data,

if elastic_settings.json is in fixtures dir

./manage.py loaddata elastic_settings

delete all data from APP

python manage.py migrate ${APPNAME} zero
python manage.py migrate ${APPNAME}    

5 STEP Load data

./manage.py loaddata attributes.json

**Allow problem

pip install django-cors-headers

than add to settings.py

INSTALLED_APPS = [
    ...
    'corsheaders',
    ...
]

CORS_ORIGIN_ALLOW_ALL = True

MIDDLEWARE = [
    ...
    'corsheaders.middleware.CorsMiddleware',
    ...
] 

Add docs for django rest gramework

Add Middleware Class for LOGGING

Add Class with free access privilegies to rest api

TESTING

run all tests

./manage.py test

run tests from app

./manage.py test apps.data_graph

run tests module

./manage.py test apps.data_graph.tests.DataGraphModelsTest

run test method

./manage.py test apps.data_graph.tests.DataGraphModelsTest.test_data

FRONTEND

from the root of our project execute

mkdir frontend && cd frontend
create-react-app .

npm i --save bootstrap
npm i --save react-bootstrap

add routes

npm i --save react-router-dom

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.