From baa9d67d182016529b3aecb0f4852b000493f2ef Mon Sep 17 00:00:00 2001 From: Conrad Date: Wed, 7 Oct 2020 10:35:14 +0200 Subject: [PATCH] Added django project --- .gitignore | 74 +++---------------- src/home/admin.py | 3 + src/home/apps.py | 5 ++ src/home/models.py | 3 + src/home/templates/home/index.html | 0 src/home/urls.py | 0 src/home/views.py | 3 + src/manage.py | 22 ++++++ src/ub/asgi.py | 16 +++++ src/ub/settings.py | 112 +++++++++++++++++++++++++++++ src/ub/urls.py | 9 +++ src/ub/wsgi.py | 16 +++++ 12 files changed, 198 insertions(+), 65 deletions(-) create mode 100644 src/home/admin.py create mode 100644 src/home/apps.py create mode 100644 src/home/models.py create mode 100644 src/home/templates/home/index.html create mode 100644 src/home/urls.py create mode 100644 src/home/views.py create mode 100755 src/manage.py create mode 100644 src/ub/asgi.py create mode 100644 src/ub/settings.py create mode 100644 src/ub/urls.py create mode 100644 src/ub/wsgi.py diff --git a/.gitignore b/.gitignore index f813275..935edda 100644 --- a/.gitignore +++ b/.gitignore @@ -1,69 +1,13 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# Typescript v1 declaration files -typings/ - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# dotenv environment variable files -.env* - -# gatsby files -.cache/ -public +# Environments +.env/ +env/ # Mac files .DS_Store -# Yarn -yarn-error.log -.pnp/ -.pnp.js -# Yarn Integrity file -.yarn-integrity +# Python files +__init__.py +__pycache__/ + +# Django Database +db.sqlite3 diff --git a/src/home/admin.py b/src/home/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/src/home/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/src/home/apps.py b/src/home/apps.py new file mode 100644 index 0000000..90dc713 --- /dev/null +++ b/src/home/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class HomeConfig(AppConfig): + name = 'home' diff --git a/src/home/models.py b/src/home/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/src/home/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/src/home/templates/home/index.html b/src/home/templates/home/index.html new file mode 100644 index 0000000..e69de29 diff --git a/src/home/urls.py b/src/home/urls.py new file mode 100644 index 0000000..e69de29 diff --git a/src/home/views.py b/src/home/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/src/home/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/src/manage.py b/src/manage.py new file mode 100755 index 0000000..b7752d6 --- /dev/null +++ b/src/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', 'ub.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/src/ub/asgi.py b/src/ub/asgi.py new file mode 100644 index 0000000..0877d1d --- /dev/null +++ b/src/ub/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for ub 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/3.1/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ub.settings') + +application = get_asgi_application() diff --git a/src/ub/settings.py b/src/ub/settings.py new file mode 100644 index 0000000..065f1ea --- /dev/null +++ b/src/ub/settings.py @@ -0,0 +1,112 @@ +""" +Django settings for ub project. + +""" + +from pathlib import Path +import os +# 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/3.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = os.environ.get("SECRET_KEY", "TEST123#") + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + '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 = 'ub.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 = 'ub.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.1/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.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/3.1/topics/i18n/ +LANGUAGE_CODE = 'de' +TIME_ZONE = 'Europe/Berlin' +USE_I18N = True +USE_L10N = True +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.1/howto/static-files/ +STATIC_URL = '/static/' + +# Media paths for serving uploaded files +MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') +MEDIA_URL = '/media/' +LOGIN_URL = '/login' diff --git a/src/ub/urls.py b/src/ub/urls.py new file mode 100644 index 0000000..cac7770 --- /dev/null +++ b/src/ub/urls.py @@ -0,0 +1,9 @@ +"""ub URL Configuration +""" +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('', include('home.urls')), + path('admin/', admin.site.urls) +] diff --git a/src/ub/wsgi.py b/src/ub/wsgi.py new file mode 100644 index 0000000..6950044 --- /dev/null +++ b/src/ub/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for ub 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/3.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ub.settings') + +application = get_wsgi_application()