in the beginning
This commit is contained in:
parent
79b67320ef
commit
62cd51a04c
13 changed files with 122 additions and 78 deletions
|
@ -1,44 +1,18 @@
|
|||
"""
|
||||
Django settings for cms project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 5.1.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.1/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/5.1/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/5.1/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-b9md6nzc0(62ui4+6(=n9gw**rr5_lnq%f7-s675d&f0&8qf(+'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'unfold',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'cmsMain'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
|
@ -48,9 +22,7 @@ MIDDLEWARE = [
|
|||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'cms.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
|
@ -66,24 +38,13 @@ TEMPLATES = [
|
|||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'cms.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
|
@ -98,26 +59,9 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/5.1/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
LANGUAGE_CODE = 'ru-ru'
|
||||
TIME_ZONE = 'Europe/Moscow'
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/5.1/howto/static-files/
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
19
cms/urls.py
19
cms/urls.py
|
@ -1,22 +1,7 @@
|
|||
"""
|
||||
URL configuration for cms project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/5.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 path
|
||||
from django.urls import path, include
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('',include('cmsMain.urls'))
|
||||
]
|
||||
|
|
0
cmsMain/__init__.py
Normal file
0
cmsMain/__init__.py
Normal file
19
cmsMain/admin.py
Normal file
19
cmsMain/admin.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin,GroupAdmin
|
||||
from django.contrib.auth.models import User, Group
|
||||
from unfold.admin import ModelAdmin
|
||||
from .models import Site, Page
|
||||
admin.site.unregister(Group)
|
||||
admin.site.unregister(User)
|
||||
|
||||
@admin.register(User)
|
||||
class UserAdmin(UserAdmin, ModelAdmin): pass
|
||||
|
||||
@admin.register(Group)
|
||||
class GroupAdmin(GroupAdmin, ModelAdmin): pass
|
||||
|
||||
@admin.register(Site)
|
||||
class SiteAdmin(ModelAdmin): pass
|
||||
|
||||
@admin.register(Page)
|
||||
class PageAdmin(ModelAdmin): pass
|
7
cmsMain/apps.py
Normal file
7
cmsMain/apps.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CmsmainConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'cmsMain'
|
||||
verbose_name = "Главная"
|
38
cmsMain/migrations/0001_initial.py
Normal file
38
cmsMain/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# Generated by Django 5.1 on 2024-08-11 18:57
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Page',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('content', models.TextField(verbose_name='Содержимое')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Страница',
|
||||
'verbose_name_plural': 'Страницы',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Site',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('domain', models.CharField(max_length=50, verbose_name='Домен')),
|
||||
('base_page', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='cmsMain.page', verbose_name='Базовая страница')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Сайт',
|
||||
'verbose_name_plural': 'Сайты',
|
||||
},
|
||||
),
|
||||
]
|
0
cmsMain/migrations/__init__.py
Normal file
0
cmsMain/migrations/__init__.py
Normal file
18
cmsMain/models.py
Normal file
18
cmsMain/models.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class Page(models.Model):
|
||||
content = models.TextField("Содержимое")
|
||||
class Meta:
|
||||
verbose_name = "Страница"
|
||||
verbose_name_plural = "Страницы"
|
||||
|
||||
class Site(models.Model):
|
||||
domain = models.CharField("Домен",max_length=50)
|
||||
base_page = models.ForeignKey(Page,on_delete=models.PROTECT,verbose_name="Базовая страница")
|
||||
def __str__(self) -> str:
|
||||
return self.domain
|
||||
class Meta:
|
||||
verbose_name = "Сайт"
|
||||
verbose_name_plural = "Сайты"
|
11
cmsMain/templates/index.html
Normal file
11
cmsMain/templates/index.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
{{content|safe}}
|
||||
</body>
|
||||
</html>
|
3
cmsMain/tests.py
Normal file
3
cmsMain/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
6
cmsMain/urls.py
Normal file
6
cmsMain/urls.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.urls import path, include
|
||||
from .views import MainView
|
||||
|
||||
urlpatterns = [
|
||||
path('',MainView.as_view())
|
||||
]
|
10
cmsMain/views.py
Normal file
10
cmsMain/views.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from django.shortcuts import render, get_object_or_404
|
||||
from django.views import View
|
||||
from .models import Site
|
||||
|
||||
class MainView(View):
|
||||
def get(self,request):
|
||||
site = get_object_or_404(Site,domain=request.META["HTTP_HOST"])
|
||||
return render(request,"index.html", {
|
||||
"content": site.base_page.content
|
||||
})
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
Django==5.1
|
||||
tzdata==2024.1
|
||||
django-unfold==0.34.0
|
Loading…
Reference in a new issue