From 98d7a05e8a6bfe939cad2cd40c5d60649bd17a9d Mon Sep 17 00:00:00 2001 From: DeevEV Date: Tue, 14 Apr 2026 11:45:00 +0300 Subject: [PATCH] lab-1: initial django project --- lab-1/lab1/__init__.py | 0 lab-1/lab1/asgi.py | 16 +++++ lab-1/lab1/settings.py | 132 +++++++++++++++++++++++++++++++++++++++++ lab-1/lab1/urls.py | 13 ++++ lab-1/lab1/wsgi.py | 16 +++++ lab-1/manage.py | 22 +++++++ lab-1/requirements.txt | 7 +++ 7 files changed, 206 insertions(+) create mode 100644 lab-1/lab1/__init__.py create mode 100644 lab-1/lab1/asgi.py create mode 100644 lab-1/lab1/settings.py create mode 100644 lab-1/lab1/urls.py create mode 100644 lab-1/lab1/wsgi.py create mode 100644 lab-1/manage.py create mode 100644 lab-1/requirements.txt diff --git a/lab-1/lab1/__init__.py b/lab-1/lab1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lab-1/lab1/asgi.py b/lab-1/lab1/asgi.py new file mode 100644 index 0000000..1351cca --- /dev/null +++ b/lab-1/lab1/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for lab1 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/6.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'lab1.settings') + +application = get_asgi_application() diff --git a/lab-1/lab1/settings.py b/lab-1/lab1/settings.py new file mode 100644 index 0000000..b0a6aa3 --- /dev/null +++ b/lab-1/lab1/settings.py @@ -0,0 +1,132 @@ +""" +Django settings for lab1 project. + +Generated by 'django-admin startproject' using Django 6.0.3. + +For more information on this file, see +https://docs.djangoproject.com/en/6.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/6.0/ref/settings/ +""" + +from pathlib import Path + +# 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/6.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure--xqwhdo2$)n*y3yk=d*vmwx6nuwt8h=m5@_og_uzj+11^hu7))' + +# 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', + + 'rest_framework', + 'quiz', +] + +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 = 'lab1.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'lab1.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/6.0/ref/settings/#databases + +import os + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': os.environ.get('POSTGRES_DB', 'lab_db'), + 'USER': os.environ.get('POSTGRES_USER', 'django'), + 'PASSWORD': os.environ.get('POSTGRES_PASSWORD', '03042004'), + 'HOST': os.environ.get('POSTGRES_HOST', 'localhost'), + 'PORT': os.environ.get('POSTGRES_PORT', 5432), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/6.0/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/6.0/topics/i18n/ + +LANGUAGE_CODE = 'ru-ru' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/6.0/howto/static-files/ + +STATIC_URL = 'static/' +STATIC_ROOT = BASE_DIR / 'staticfiles' + +# Default primary key field type +# https://docs.djangoproject.com/en/6.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/lab-1/lab1/urls.py b/lab-1/lab1/urls.py new file mode 100644 index 0000000..e617532 --- /dev/null +++ b/lab-1/lab1/urls.py @@ -0,0 +1,13 @@ +from django.contrib import admin +from django.urls import path, include +from rest_framework import routers +from quiz.views import QuizViewSet + +router = routers.DefaultRouter() +router.register(r'quiz', QuizViewSet) + +urlpatterns = [ + path('admin/', admin.site.urls), + path('api/', include(router.urls)), +] + diff --git a/lab-1/lab1/wsgi.py b/lab-1/lab1/wsgi.py new file mode 100644 index 0000000..4716070 --- /dev/null +++ b/lab-1/lab1/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for lab1 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/6.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'lab1.settings') + +application = get_wsgi_application() diff --git a/lab-1/manage.py b/lab-1/manage.py new file mode 100644 index 0000000..cfc0053 --- /dev/null +++ b/lab-1/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', 'lab1.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/lab-1/requirements.txt b/lab-1/requirements.txt new file mode 100644 index 0000000..1f33642 --- /dev/null +++ b/lab-1/requirements.txt @@ -0,0 +1,7 @@ +djangorestframework +markdown +django-filter +django-cors-headers +psycopg[binary,pool] +faker +gunicorn