[ Django & DRF ] django-all-about, can be a good study material for someone and a good boilerplate for someone

Overview

All About Django (almost)

Django 로 가능한 다양한 형태의 실습, 테스트 케이스 complex - boilerplate

  • 우선 config, settings 값 등 환경 변수로 다뤄야 할 것들을 철저하게 단순 테스트를 위해 파일에 같이 저장되어 있는 점 유의
  • DB 관련도 DBMS와 소통할 때 no-auth 에 localhost 인 점도 꼭 유의
  • Django 에서 User와 Auth(Permission) 에 대한 부분은 철저하게 core만 사용함. 커스텀 없음
  • exception에 대해서도 커스텀 없음.

Infra & Requirements

  • Django
  • DRF (Django RestFrameWork)
  • Gunicorn (wsgi)
  • Celery, Celery Beat
  • Redis
  • Postgresql
  • Mongodb
  • Nginx

Getting Start

project init

  • git clone
  • docker 디렉토리로 가서 docker-start.sh 실행 (ex - source docker-start.sh)
  • python -m venv .venv 가상환경은 직접 편한 방식으로 생성
  • pip install -r requirements.txt
  • python manage.py migrate
  • python manage.py migrate --database=orders 다중 데이터베이스 세팅으로 꼭 해주셔야 합니다.
  • 디렉토리 만들기, django_all_about >> logs file logging을 사용하기 때문에 디렉토리 만들어줘야합니다.
  • python manage.py runserver 정상 작동 테스트 후 exit
  • 서버 러닝이 정상 작동 한다면, super user 생성하기, python manage.py createsuperuser
  • python manage.py collectstatic 로 static file 생성 까지 진행
  • python manage.py runserver 를 통해 http://localhost/admin 으로 접속
    • 아니 8000으로 바인딩했으면서 왜 80으로 가냐? docker - nginx conf 참조, 리버스 프록시 세팅 모두 되어있음

detail config

  1. mongo user 만들기
  • mongo container shell 접근
  • mongo --host 127.0.0.1 --port 29019
use admin
db.createUser(
  {
    user: "nuung",
    pwd:  "daa123!",
    roles: [ { role: "root", db: "admin" } ]
  }
)
db.runCommand('usersInfo')
  • 이후 settings > local.py 의 DB 값 에서 다음 값을 바꿔주면 된다.
            # 'username': '몽고DB 사용자 계정을 넣어주세요',
            # 'password': "몽고DB 사용자 비밀번호 넣어주세요",
            ...
            'username': 'nuung',
            'password': 'daa123!',
  1. app 추가를 하려면
  • 우선 apis 하위에 추가하려는 app의 디렉토리 (폴더)를 하나 추가한다.
  • 그리고 python manage.py startapp products ./apis/products 커멘드로 세팅한다
  • urls.pyserializers.py 추가로 세팅해서 사용하면 된다.
  • apps.py 세팅값도 살짝 바꾸는게 좋은데, 이미 있는 것을 참고하길 바란다.
  1. 분리된 config > setting 에서 manage.py shell 에 접근할 때에는 python manage.py shell --settings=config.settings.local 와 같이 option을 추가해 줘야 한다.

  2. 기본적인 url 들은 아래와 같다

  • localhost : main, index but not used
  • localhost/admin ; django의 핵심, admin 페이지 이다.
  • localhost/swagger/ : 스웨거는 꼭 들어가 보길, 말그대로 swagger로 API 정리되어있는 문서다. drf와 drf_yasg 의 합작이다.
  • localhost/api/... : API endpoint 의 pre-fix로 "api" 가 붙는다.
  1. django 파일 빈번하게 바꾸면서 테스트할 꺼라면, django를 도커라이징에서 제외하고 사용하는 것을 추천 (기본 세팅)

Case

1. 전체 프로젝트 도커라이징 및 다중 데이터베이스 활용하기

  • config > dbrouter.py 부분과 config > settings > local.py 에서 Database setting 부분을 참조해 보자
  • model에 app_lable 을 붙이는 것과 migrate 진행시 database option을 주는 것

2. N:M 을 다루기

  • OrderRequest 에서 출발을 해서, 해당 유저가 구매요청에 해당하는 모든 item을 찾아보자

3. admin을 admin 답게 커스텀하기

4. Django middleware 만들기

  • HttpRequest -> HttpResponse 이 처리 구간에서 time library의 process_time_ns 함수를 활용해서 응답 헤더에 추가해 보자.

5. DRF response, request 커스텀 자유롭게 하기

6. Model field index와 퍼포먼스 체커

You might also like...

Also able to be used if someone leaks his Tokens and you dont know what Server the Bot is in

Discord Nuker made with Python A Nuker I made with commands such as Ban all Kick all Nick all DM all Nuke Guildnuke Guilds VC Spam Channel Spam Catego

May 23, 2022

Auto Saves Messages When Someone Dm You, Made By blob#0005

Discord-Selfbot-Dms-Message-Auto-Saver Setup: download python (https://python.org) open the file that u downloaded click add to path then next wait un

Sep 10, 2022

A working Discord token generator, was developed by someone called vichy.

A working Discord token generator, was developed by someone called vichy. this is a leak of it. has working AI captcha solver, all you need is proxies. Can make mail verified tokens if you have a API key for one of the mail providers in the config.toml

Dec 9, 2022

Simple Bot For Notifying You When You Were Tagged In A Group, Simply This Bot Will Inform You In Your Log Group When Someone Tagged You In Ga Group

Simple Bot For Notifying You When You Were Tagged In A Group, Simply This Bot Will Inform You In Your Log Group When Someone Tagged You In Ga Group

❤️ TAG INFORMER BOT ❤️ Simple Bot for Notifying You When You Were Tagged In A Group ... Written With Python and Telethon... ⭐️ Thanks to everyone for

Oct 20, 2022

AI to Recognize someone's face from an image

AI to Recognize someone's face from an image

face_recognition_cnn Description AI to recognize from face images. It is a convolutional neural network (CNN) based face recognition system. The proje

Dec 18, 2022

Fox CC a Good CC tools that you can generate and validate a cc !

Fox CC [-] Black Fox CC Tools Features [&] Fast & easy [&] Generate a valid card [&] Generate multi valid card [&] Credit Card Valid Checker [&] Witho

Dec 26, 2022

Fox CC a Good CC tools that you can generate and validate a cc !

Fox CC [-] Black Fox CC Tools Features [&] Fast & easy [&] Generate a valid card [&] Generate multi valid card [&] Credit Card Valid Checker [&] Gener

Aug 24, 2022

✨This is an pyqt5 example.🔥Good project structure. 💻It can be used directly for rapid development.

✨This is an pyqt5 example.🔥Good project structure. 💻It can be used directly for rapid development.

pyqt5_example 中文 ✨ This is an pyqt5 example 🔥 . 💻 It can be used directly for rapid development. Some other functions will be added later, such as c

Nov 9, 2022
Owner
HyeonWoo Jeong
항상 새로운 것에 도전하고 노력하는 개발자가 되겠습니다.
HyeonWoo Jeong
A tool to help you fuck up someone's server real good

discord-nuke-tool A tool to help you fuck up someone's server real good add your user token in config.json in your terminal run pip install -r require

null 3 Sep 27, 2022
Contains key documentations of my masterthesis. Includes code for computing counterfactual explanations, layout of user study and analysis code of the study results.

Evaluating the Practicality of Counterfactual Explanations This repository holds key information about my Masterthesis (18 EC) for the Master's degree

Nina Spreitzer 1 Sep 15, 2022
An easy-to-use Python HTTP framework based on Flask blueprint with some Django features, e.g., DRF

Fango An easy-to-use Python HTTP framework based on Flask blueprint with some Django features, e.g., DRF, middleware, ORM Where Fango comes from Fango

Gnomeek 1 Apr 24, 2022
Social network "CuBe" (DRF, Django, Js)

TheCubeSocialNetwork Social network "CuBe" (DRF, Django, Js) in case of errors https://google.com/ will help you ;) May manage.py be with you. ⚡️ Run:

Yolkin ;3 5 Sep 19, 2022
To-Do DRF APP Using React

To-Do Django Rest APP ?? Vitrine.Dev ✨ Nome To-Do App ??️ Tecnologias python, django rest, postgresql, react A To-Do APP made with Django REST and Rea

Marcus Vinícius 1 Sep 13, 2022
drf-library-api-Tomtuhtomtom created by GitHub Classroom

DRF Library API Create a new API-only application that lets users keep track of books, including important information like title, author, publication

Momentum Team 14 1 Sep 16, 2022
Download all docent's documents in docenti.unina teaching material (using unina credentials)

UninaDownloader Download all docent's documents in docenti.unina teaching material (using unina credentials) Download instruction Clone the repository

Tony177 2 Jul 10, 2022
This is a boilerplate for a Web Application using Django for backend and React for frontend. This is based on the testdrive.io tutorial.

DJANGO REACT APPLICATION This is a boilerplate for an application using Django for the backend and React for the frontend of a web application. This d

Ryan Nicholas 1 May 25, 2022
Boilerplate Django Blog for production deployments! (COMING SOON!)

CFE Django Blog THIS IS COMING SOON This is boilerplate code that you can use to learn how to bring Django into production. TLDR; This is definitely c

Coding For Entrepreneurs 26 Dec 9, 2022