Актуальный сборник шаблонов для создания проектов и приложений на Django

Overview

О чем этот проект

Этот репозиторий с шаблонами для быстрого создания Django проекта.


В шаблоне проекта настроены следующий технологий:

  • Django
  • gunicorn (В качестве WSGI сервера)
  • Django Ninja (В качестве REST API)
  • Docker
  • Docker-compose
  • Nginx (Через Docker-compose)
  • PostgreSQL (Через Docker-compose)
  • .env (Все важные настройки проекта хранятся в переменных окружения)
  • Makefile (Готовые стандартные команды для работы с проектом)
  • npm
  • React (Для рендеринга шаблонов)
  • webpack.config.js (Для автоматической сборки React при изменении файлов)
  • .gitignore && .dockerignore

Установка

Наша задача скопировать(с заменой) данные шаблон в папку где хранятся стандартные шаблоны Djnago.


Вот пример замены стандартных шаблонов Django на наши, будем использовать виртуальное окружение venv, и Linux. ( Этот скрипт можно выполнить за одну команду).

# Создаем папку со всем проектом, И переходим в неё
dir="ИмяПроекта";
mkdir ${dir} && cd ${dir};
# Копируем этот репозиторий.
git clone https://github.com/denisxab/django-start-pack.git .;
# На всякий случай выходим из ВО если мы в нем находимся.
deactivate;
# Создаем виртуальное окружение, Актируем его, устанавливаем `Django`.
python -m venv venv && . ./venv/bin/activate && pip install Django;
# Создаем переменную с версий текущего ВО `Python`.
py_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))');
# Удаляем стандартные шаблон проекта и приложения `Django`.
rm -rf ./venv/lib/python${py_version}/site-packages/django/conf/project_template ./venv/lib/python${py_version}/site-packages/django/conf/app_template;
# Копируем шаблоны из репозитория в ВО.
cp -r project_template ./venv/lib/python${py_version}/site-packages/django/conf/ &&
cp -r app_template ./venv/lib/python${py_version}/site-packages/django/conf/ &&
# Удаляем ненужные файлы/папки.
rm -rf project_template app_template .git;
# Показать результат `Django` шаблона
tree ./venv/lib/pythonn${py_version}/site-packages/django/conf/project_template &&
tree ./venv/lib/pythonn${py_version}/site-packages/django/conf/app_template;

Использование

Создать проект (-e указывает расширение файлов которые нужно отрендерить как шаблон)

django-admin startproject <ИмяПроекта> -e py,env,dockerignore,gitignore,json;

Создать приложение (-e указывает расширение файлов которые нужно отрендерить как шаблон)

django-admin startapp <ИмяПриложения> -e py,env,dockerignore,gitignore,json;

Настроим и запустим проект.

cd <ИмяПроекта>;
# Первоначально настраиваем проект
make init_proj;
# Запуска `webpack`
make webpack_run;
# Запускам `Django` сервер (запустите в новом окне)
make dj_run;

И теперь можно начинать разрабатывать свой проект, не задумываться о первоначальных настройках.

Особенности созданного проекта через этот шаблон

  • Главное приложение теперь имеет название conf
  • Файл с переменными окружения называется __env.env
  • Все настройки проекта хранят в файле с переменными окружения ./__env.env. Его нужно держать в тайне, так как в нём будут храниться приватные настройки для БД и Django. Он уже занесен в .gitignore && .dockerignore
  • Для быстрого и удобного исполнения команд есть ./Makfile. Для исполнения этого файла необходимо иметь программу make . На Ubuntu можно скачать эту программу командой sudo apt install make.
  • Есть файл ./Dockerfile для создания контейнера с проектом. make docker_build - собрать образ (Для правильной сборки образа и контейнера прочитайте Makfile в нем уже реализованы все необходимые настройки).
  • Есть файл ./docker-compose.yml для создания контейнера с PostgreSQL и nginx. make docker_compose_up - запустить контейнеры (Для правильной сборки образа и контейнера прочитайте Makfile в нем уже реализованы все необходимые настройки).
  • В папке ./deploy/gunicorn хранятся настройки для запуска gunicorn, в этой же папке будут храниться логи от gunicorn.
  • В папке ./ <имяпроекта> /__cache храниться кеш Django. Название этой папки определено настройками settings.py->CACHES->"default"->"LOCATION"->"__cache"
  • В папке db будет храниться volumes(термин из Docker) для БД.
  • В качестве шаблонизатор будем использовать React который храниться в приложение frontend_react. Главный компонент React находиться по пути ИмяПроекта->frontend_react->src->App.js
  • Скомпилированный код webpack храниться по пути ИмяПроекта->frontend_react->static->frontend_react->public->main.js

Особенности созданного приложения через этот шаблон

  • Есть папки static, templates, templatetags
  • Есть предварительные шаблоны для моделей и админ панели
Owner
Denis Kustov
Human
Denis Kustov
django-tables2 - An app for creating HTML tables

django-tables2 - An app for creating HTML tables django-tables2 simplifies the task of turning sets of data into HTML tables. It has native support fo

Jan Pieter Waagmeester 1.6k Jan 03, 2023
A reusable Django model field for storing ad-hoc JSON data

jsonfield jsonfield is a reusable model field that allows you to store validated JSON, automatically handling serialization to and from the database.

Ryan P Kilby 1.1k Jan 03, 2023
A real-time photo feed using Django and Pusher

BUILD A PHOTO FEED USING DJANGO Here, we will learn about building a photo feed using Django. This is similar to instagram, but a stripped off version

samuel ogundipe 4 Jan 01, 2020
Django server-side adapter for Inertia.js

django-inertia Django server-side new adapter for Inertia.js. Getting Started Install the package pip install django-inertia Configure your project A

Samuel Girardin 14 Sep 16, 2022
File and Image Management Application for django

Django Filer django Filer is a file management application for django that makes handling of files and images a breeze. Contributing This is a an open

django CMS Association 1.6k Dec 28, 2022
Learn Python and the Django Framework by building a e-commerce website

The Django-Ecommerce is an open-source project initiative and tutorial series built with Python and the Django Framework.

Very Academy 275 Jan 08, 2023
Utilities for implementing a modified pre-order traversal tree in django.

django-mptt Utilities for implementing Modified Preorder Tree Traversal with your Django Models and working with trees of Model instances. Project hom

2.7k Jan 01, 2023
Visual DSL framework for django

Preface Processes change more often than technic. Domain Rules are situational and may differ from customer to customer. With diverse code and frequen

Dmitry Kuksinsky 165 Jan 08, 2023
A CBV to handle multiple forms in one view

django-shapeshifter A common problem in Django is how to have a view, especially a class-based view that can display and process multiple forms at onc

Kenneth Love 167 Nov 26, 2022
scaffold django rest apis like a champion 🚀

dr_scaffold Scaffold django rest apis like a champion ⚡ . said no one before Overview This library will help you to scaffold full Restful API Resource

Abdenasser Elidrissi 133 Jan 05, 2023
pytest-django allows you to test your Django project/applications with the pytest testing tool.

pytest-django allows you to test your Django project/applications with the pytest testing tool.

pytest-dev 1.1k Dec 14, 2022
Set the draft security HTTP header Permissions-Policy (previously Feature-Policy) on your Django app.

django-permissions-policy Set the draft security HTTP header Permissions-Policy (previously Feature-Policy) on your Django app. Requirements Python 3.

Adam Johnson 78 Jan 02, 2023
A better and faster multiple selection widget with suggestions

django-searchable-select A better and faster multiple selection widget with suggestions for Django This project is looking for maintainers! Please ope

Andrew Dunai 105 Oct 22, 2022
Indonesia's negative news detection using gaussian naive bayes with Django+Scikir Learn

Introduction Indonesia's negative news detection using gaussian naive bayes build with Django and Scikit Learn. There is also any features, are: Input

Harifzi Ham 1 Dec 30, 2021
A UUIDField for Django

django-uuidfield Provides a UUIDField for your Django models. Installation Install it with pip (or easy_install): pip install django-uuidfield Usage

David Cramer 265 Nov 30, 2022
Hotwired/Turbo Django response helpers

This package provides helpers for server-side rendering of Hotwired/Turbo streams and frames. Disclaimer: the Hotwired/Turbo client libraries are, at

Hotwire for Django 66 Apr 07, 2022
Twitter Bootstrap for Django Form

Django bootstrap form Twitter Bootstrap for Django Form. A simple Django template tag to work with Bootstrap Installation Install django-bootstrap-for

tzangms 557 Oct 19, 2022
An URL Shortener with Basic Features.

Simple Url Shortener What is that? Yet another url shortener built with Django framework. Preview HOW TO RUN? 1. Virtual Environment First create a vi

Ethem Turgut 6 Jan 25, 2022
English dictionary using Django based on freecodecamp

English Dictionary Hi there, i made this english dictionary using Django based on freecodecamp.org tutorial :) Table of Contents Preview Technologies

Aline Alencar 3 May 09, 2022
Extensions for using Rich with Django.

django-rich Extensions for using Rich with Django. Requirements Python 3.6 to 3.10 supported. Django 2.2 to 4.0 supported. Are your tests slow? Check

Adam Johnson 88 Dec 26, 2022