diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b341808 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.pyc +*.DS_Store +*.egg* +/dist/ +/.idea +/docs/_build/ +/node_modules/ +build/ +env +/staticfiles/ + +#src +*.sqlite* + +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..253fafb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3.9 + +# set environment variables +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +COPY requirements.txt . +# install python dependencies +RUN pip install --upgrade pip +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +# running migrations +RUN python manage.py migrate + +# gunicorn +CMD ["gunicorn", "--config", "gunicorn-cfg.py", "core.wsgi"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..12d350f --- /dev/null +++ b/README.md @@ -0,0 +1,94 @@ +# [Django Material Dashboard](https://appseed.us/product/material-dashboard/django/) + +Open-source **Django** project crafted on top of **Material Dashboard**, an open-source `Boostrap 5` design from [Creative-Tim](https://bit.ly/3fKQZaL) +The product is designed to deliver the best possible user experience with highly customizable feature-rich pages. `Material Material` has easy and intuitive responsive design whether it is viewed on retina screens or laptops. + +- 👉 [Django Material Dashboard](https://appseed.us/product/material-dashboard/django/) - `Product page` +- 👉 [Django Material Dashboard](https://django-material-dashboard.onrender.com) - `LIVE Demo` +- 🚀 Free [Support](https://appseed.us/support/) via `Email` & `Discord` + +
+ +> Features: + +- ✅ `Up-to-date Dependencies` +- ✅ Theme: [Django Admin Material](https://github.com/app-generator/django-admin-material-dashboard) +- ✅ **Authentication**: `Django.contrib.AUTH`, Registration +- 🚀 `Deployment` + - `CI/CD` flow via `Render` + - [Go LIVE with Django Material Dashboard](https://www.youtube.com/watch?v=ShQKSf5y7mI) - `video presentation` + +
+ +![Material Dashboard - Full-Stack Starter generated by AppSeed.](https://user-images.githubusercontent.com/51070104/169301658-6cf27993-c451-4cd4-9ffa-2968b8981167.png) + +
+ +## Manual Build + +> 👉 Download the code + +```bash +$ git clone https://github.com/app-generator/django-material-dashboard.git +$ cd django-material-dashboard +``` + +
+ +> 👉 Install modules via `VENV` + +```bash +$ virtualenv env +$ source env/bin/activate +$ pip install -r requirements.txt +``` + +
+ +> 👉 Set Up Database + +```bash +$ python manage.py makemigrations +$ python manage.py migrate +``` + +
+ +> 👉 Create the Superuser + +```bash +$ python manage.py createsuperuser +``` + +
+ +> 👉 Start the app + +```bash +$ python manage.py runserver +``` + +At this point, the app runs at `http://127.0.0.1:8000/`. + +
+ +## Screenshots + +This design is a pixel-perfect [Bootstrap 5](https://www.admin-dashboards.com/bootstrap-5-templates/) Dashboard with a fresh, new design inspired by Google's Material Design. **Material Dashboard** is built with over 60 frontend individual elements, like buttons, inputs, navbars, nav tabs, cards, or alerts, giving you the freedom of choosing and combining. + +
+ +> **[Django Admin Material](https://github.com/app-generator/django-admin-material-dashboard)** - `Admin Section` + +![Django Admin Material Dashboard - Admin dashboard page.](https://user-images.githubusercontent.com/51070104/196743760-6e0e1930-8233-421c-ac53-d65c273b00dc.png) + +
+ +> **[Django Admin Material](https://github.com/app-generator/django-admin-material-dashboard)** - `Admin Widgets` + +![Django Admin Material Dashboard - New User Page.](https://user-images.githubusercontent.com/51070104/196743821-2e140dd8-fe15-4615-9e9f-0467900b1a1b.png) + +
+ +--- +[Django Material Dashboard](https://appseed.us/product/material-dashboard/django/) - Minimal **Django** core provided by **[AppSeed](https://appseed.us/)** diff --git a/README_deploy.md b/README_deploy.md new file mode 100644 index 0000000..a1ac7e5 --- /dev/null +++ b/README_deploy.md @@ -0,0 +1,24 @@ +# How to deploy on `Render` + +> This document should contains all the steps to deploy the app on render without much effort, using PostgreSQL + +https://render.com/docs/deploy-django + +## ALL STEPS below + +
+ +### 👉 Create `PostgreSQL` database on render + - Go to https://dashboard.render.com/new/database this link. + - Database name should be `berry`. + - Keep the Database, User and Datadog API Key as it is. + - If you want to change database name anything else then you have to change your `render.yaml` file database name too. + +
+ +### 👉 Create a Blueprint instance + - Go to https://dashboard.render.com/blueprints this link. + - Click `New Blueprint Instance` button. + - Connect your `repo` which you want to deploy. + - Fill the `Service Group Name` and click on `Update Existing Resources` button. + - After that your deployment will start automatically. \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..475c139 --- /dev/null +++ b/build.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# exit on error +set -o errexit + +python -m pip install --upgrade pip + +pip install -r requirements.txt + +python manage.py collectstatic --no-input +python manage.py migrate diff --git a/core/__init__.py b/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/asgi.py b/core/asgi.py new file mode 100644 index 0000000..26a5940 --- /dev/null +++ b/core/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for core project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings") + +application = get_asgi_application() diff --git a/core/settings.py b/core/settings.py new file mode 100644 index 0000000..9dbd3b5 --- /dev/null +++ b/core/settings.py @@ -0,0 +1,160 @@ +""" +Django settings for core project. + +Generated by 'django-admin startproject' using Django 4.1.2. + +For more information on this file, see +https://docs.djangoproject.com/en/4.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.1/ref/settings/ +""" + +import os, random, string +from pathlib import Path +from dotenv import load_dotenv + +load_dotenv() # take environment variables from .env. + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = os.environ.get('SECRET_KEY') +if not SECRET_KEY: + SECRET_KEY = ''.join(random.choice( string.ascii_lowercase ) for i in range( 32 )) + +# Render Deployment Code +DEBUG = 'RENDER' not in os.environ + +ALLOWED_HOSTS = [] + +RENDER_EXTERNAL_HOSTNAME = os.environ.get('RENDER_EXTERNAL_HOSTNAME') +if RENDER_EXTERNAL_HOSTNAME: + ALLOWED_HOSTS.append(RENDER_EXTERNAL_HOSTNAME) + +# Application definition + +INSTALLED_APPS = [ + 'admin_material.apps.AdminMaterialDashboardConfig', + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + + "home", +] + +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "whitenoise.middleware.WhiteNoiseMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", +] + +ROOT_URLCONF = "core.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ], + }, + }, +] + +WSGI_APPLICATION = "core.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/4.1/ref/settings/#databases + +DB_ENGINE = os.getenv('DB_ENGINE' , None) +DB_USERNAME = os.getenv('DB_USERNAME' , None) +DB_PASS = os.getenv('DB_PASS' , None) +DB_HOST = os.getenv('DB_HOST' , None) +DB_PORT = os.getenv('DB_PORT' , None) +DB_NAME = os.getenv('DB_NAME' , None) + +if DB_ENGINE and DB_NAME and DB_USERNAME: + DATABASES = { + 'default': { + 'ENGINE' : 'django.db.backends.' + DB_ENGINE, + 'NAME' : DB_NAME, + 'USER' : DB_USERNAME, + 'PASSWORD': DB_PASS, + 'HOST' : DB_HOST, + 'PORT' : DB_PORT, + }, + } +else: + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': 'db.sqlite3', + } + } + +# Password validation +# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.1/topics/i18n/ + +LANGUAGE_CODE = "en-us" + +TIME_ZONE = "UTC" + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.1/howto/static-files/ + +STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') + +#if not DEBUG: +# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" + +LOGIN_REDIRECT_URL = '/' +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' diff --git a/core/urls.py b/core/urls.py new file mode 100644 index 0000000..989a31e --- /dev/null +++ b/core/urls.py @@ -0,0 +1,23 @@ +"""core URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.1/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import include, path + +urlpatterns = [ + path('', include('home.urls')), + path("admin/", admin.site.urls), + path("", include('admin_material.urls')) +] diff --git a/core/wsgi.py b/core/wsgi.py new file mode 100644 index 0000000..e9b9d8a --- /dev/null +++ b/core/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for core project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings") + +application = get_wsgi_application() diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d8a7514 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: '3.8' +services: + appseed-app: + container_name: appseed_app + restart: always + build: . + networks: + - db_network + - web_network + nginx: + container_name: nginx + restart: always + image: "nginx:latest" + ports: + - "5085:5085" + volumes: + - ./nginx:/etc/nginx/conf.d + networks: + - web_network + depends_on: + - appseed-app +networks: + db_network: + driver: bridge + web_network: + driver: bridge + \ No newline at end of file diff --git a/env.sample b/env.sample new file mode 100644 index 0000000..731756c --- /dev/null +++ b/env.sample @@ -0,0 +1,11 @@ +# True for development, False for production +DEBUG=True + +SECRET_KEY= + +# DB_ENGINE=mysql +# DB_HOST=localhost +# DB_NAME=appseed_db +# DB_USERNAME=appseed_db_usr +# DB_PASS=pass +# DB_PORT=3306 \ No newline at end of file diff --git a/gunicorn-cfg.py b/gunicorn-cfg.py new file mode 100644 index 0000000..3acce75 --- /dev/null +++ b/gunicorn-cfg.py @@ -0,0 +1,11 @@ +# -*- encoding: utf-8 -*- +""" +Copyright (c) 2019 - present AppSeed.us +""" + +bind = '0.0.0.0:5005' +workers = 1 +accesslog = '-' +loglevel = 'debug' +capture_output = True +enable_stdio_inheritance = True diff --git a/home/__init__.py b/home/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/home/admin.py b/home/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/home/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/home/apps.py b/home/apps.py new file mode 100644 index 0000000..e7d1c7e --- /dev/null +++ b/home/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class HomeConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "home" diff --git a/home/migrations/__init__.py b/home/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/home/models.py b/home/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/home/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/home/tests.py b/home/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/home/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/home/urls.py b/home/urls.py new file mode 100644 index 0000000..88a9cac --- /dev/null +++ b/home/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('', views.index, name='index'), +] diff --git a/home/views.py b/home/views.py new file mode 100644 index 0000000..a878981 --- /dev/null +++ b/home/views.py @@ -0,0 +1,9 @@ +from django.shortcuts import render +from django.http import HttpResponse + +# Create your views here. + +def index(request): + + # Page from the theme + return render(request, 'pages/index.html') diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..4e20ce5 --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + main() diff --git a/nginx/appseed-app.conf b/nginx/appseed-app.conf new file mode 100644 index 0000000..61c7a1e --- /dev/null +++ b/nginx/appseed-app.conf @@ -0,0 +1,15 @@ +upstream webapp { + server appseed_app:5005; +} + +server { + listen 5085; + server_name localhost; + + location / { + proxy_pass http://webapp; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + +} diff --git a/render.yaml b/render.yaml new file mode 100644 index 0000000..961cee0 --- /dev/null +++ b/render.yaml @@ -0,0 +1,15 @@ +services: + - type: web + name: django-material-dashboard + plan: starter + env: python + region: frankfurt # region should be same as your database region. + buildCommand: "./build.sh" + startCommand: "gunicorn core.wsgi:application" + envVars: + - key: DEBUG + value: False + - key: SECRET_KEY + generateValue: true + - key: WEB_CONCURRENCY + value: 4 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0b23c7d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +django +gunicorn +python-dotenv +whitenoise +django-admin-material-dashboard==1.0.5 + +# psycopg2-binary +# mysqlclient diff --git a/static/.gitkeep b/static/.gitkeep new file mode 100644 index 0000000..e69de29