unknown hai 3 meses
pai
achega
3fa9681da5

+ 124 - 124
courses/django_kind/sitewomen/sitewomen/settings.py

@@ -1,124 +1,124 @@
-"""
-Django settings for sitewomen project.
-
-Generated by 'django-admin startproject' using Django 5.1.4.
-
-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-tac__m@^ndq4-9svbw*h_al*^$cwe1u2q+tmcyax-49rebdvfs'
-
-# SECURITY WARNING: don't run with debug turned on in production!
-DEBUG = False
-
-ALLOWED_HOSTS = ['127.0.0.1', 'localhost']
-
-
-# Application definition
-
-INSTALLED_APPS = [
-    'django.contrib.admin',
-    'django.contrib.auth',
-    'django.contrib.contenttypes',
-    'django.contrib.sessions',
-    'django.contrib.messages',
-    'django.contrib.staticfiles',
-    'women.apps.WomenConfig',
-]
-
-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 = 'sitewomen.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 = 'sitewomen.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',
-    },
-    {
-        '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/5.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/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'
+"""
+Django settings for sitewomen project.
+
+Generated by 'django-admin startproject' using Django 5.1.4.
+
+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-tac__m@^ndq4-9svbw*h_al*^$cwe1u2q+tmcyax-49rebdvfs'
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = ['127.0.0.1', 'localhost']
+
+
+# Application definition
+
+INSTALLED_APPS = [
+    'django.contrib.admin',
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.messages',
+    'django.contrib.staticfiles',
+    'women.apps.WomenConfig',
+]
+
+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 = 'sitewomen.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 = 'sitewomen.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',
+    },
+    {
+        '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/5.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/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'

+ 32 - 23
courses/django_kind/sitewomen/women/templates/women/index.html

@@ -1,24 +1,33 @@
-<!DOCTYPE html>
-<head>
-    <meta charset="UTF-8">
-    <title>{{ title }}</title>
-</head>
-<body>
-<p>{{ menu|join:" | " }}</p>
-<h1>{{ title }}</h1>
-
-<ul>
-    {% for p in posts %}
-    {% if p.is_published %}
-    <li>
-        <h2>{{ p.title }}</h2>
-        <p>{{ p.content }}</p>
-        {% if not forloop.last %}
-        <hr>
-        {% endif %}
-    </li>
-    {% endfor %}
-</ul>
-
-</body>
+<!DOCTYPE html>
+<head>
+    <meta charset="UTF-8">
+    <title>{{ title }}</title>
+</head>
+<body>
+<ul>
+    <li><a href="{% url 'home' %}">Главная страница</a></li>
+    {% for m in menu %}
+    {% if not forloop.last%}<li>{% else %}<li class="last">{% endif %}
+        <a href="{% url m.url_name %}">{{ m.title }}</a>
+    </li>
+    {% endfor%}
+</ul>
+<h1>{{ title }}</h1>
+
+<ul>
+    {% for p in posts %}
+    {% if p.is_published %}
+    <li>
+        <h2>{{ p.title }}</h2>
+        <p>{{ p.content }}</p>
+        <p><a href='{% url "post" p.id %}'>Читать пост</a></p>
+        {% if not forloop.last %}
+        <hr>
+        {% endif %}
+    </li>
+    {% endif %}
+    {% endfor %}
+</ul>
+
+</body>
 </html>

+ 17 - 16
courses/django_kind/sitewomen/women/urls.py

@@ -1,17 +1,18 @@
-from django.urls import path, re_path, register_converter
-from . import views
-from . import converters
-
-
-register_converter(converters.FourDigitYearConverter, "year4")
-
-urlpatterns = [
-    path('', views.index, name='home'), # http://127.0.0.1:8000
-    path('about/', views.about, name='about'),
-    # path('details/', views.post_detail),
-    # path('posts/<int:year>', views.posts_list),
-    path('cats/<int:cat_id>/', views.categories, name='cat_id'), # http://127.0.0.1:8000/cats/1/
-    path('cats/<slug:cat_slug>/', views.categories_by_slug, name='cats'), # http://127.0.0.1:8000/cats/asdfad/
-    # re_path(r"^archive/(?P<year>[0-9]{4})", views.archive),
-    path('archive/<year4:year>', views.archive, name='archive'),
+from django.urls import path, re_path, register_converter
+from . import views
+from . import converters
+
+
+register_converter(converters.FourDigitYearConverter, "year4")
+
+urlpatterns = [
+    path('', views.index, name='home'), # http://127.0.0.1:8000
+    path('about/', views.about, name='about'),
+    path('addpage/', views.addpage, name='add_page'),
+    path('contact/', views.contact, name='contact'),
+    path('loign/', views.login, name='login'),
+    path('post/<int:post_id>/', views.show_post, name='post'),
+    # path('cats/<int:cat_id>/', views.categories, name='cat_id'), # http://127.0.0.1:8000/cats/1/
+    # path('cats/<slug:cat_slug>/', views.categories_by_slug, name='cats'), # http://127.0.0.1:8000/cats/asdfad/
+    # path('archive/<year4:year>', views.archive, name='archive'),
 ]

+ 70 - 89
courses/django_kind/sitewomen/women/views.py

@@ -1,90 +1,71 @@
-from django.shortcuts import render, redirect
-from django.http import HttpResponse, HttpResponseNotFound, Http404, HttpResponseRedirect
-from django.urls import reverse
-from django.template.loader import render_to_string
-from django.template.defaultfilters import slugify
-
-
-# Create your views here.
-
-menu = ["О сайте", "Добавить сатью", "Обратная связь", "Войти"]
-
-
-data_db = [
-    {'id': 1, 'title': 'Анджелина Джоли', 'content': 'Биография Анджелины Джоли', 'is_published': True },
-    {'id': 2, 'title': 'Марго Робби', 'content': 'Биография Марго Робби', 'is_published': False },
-    {'id': 3, 'title': 'Джулия Робертс', 'content': 'Биография Джулия Робертс', 'is_published': True },
-]
-
-
-
-def index(request): # HttRequest
-    # t = render_to_string('women/index.html')
-    # return HttpResponse(t)
-
-    # data = {'title': 'главная страница?',
-    #         'menu': menu,
-    #         'float': 234.465,
-    #         'lst': [1, 2, 'abc', True],
-    #         'set': {1, 2, 3, 4, 5},
-    #         'dict': {'key_1': 'value_1', 'key_2': 'value_2'},
-    #         'obj': MyClass(10, 20),
-    #         'url': slugify("The main page"),
-    # }
-
-    data = {'title': 'Главная страница',
-            'menu': menu,
-            'posts': data_db,
-    }
-    
-
-    return render(request, 'women/index.html', context=data)
-
-
-def about(request):
-    return render(request, 'women/about.html',  {'title': 'О сайте'})
-
-
-def categories(request, cat_id):
-    return HttpResponse(f"<h1>Статьи по категориям</h1><p>id: {cat_id}</p>")
-
-
-def categories_by_slug(request, cat_slug):
-    if request.GET:
-        print(request.GET)
-    return HttpResponse(f"<h1>Статьи по категориям</h1><p>slug: {cat_slug}</p>")
-
-
-def archive(request, year):
-    if year > 2023:
-        # return redirect('/') # код 302
-        # return redirect(index) # код 302 Можно указать функцию-представление
-        # return redirect(index) # код 302 Можно указать функцию-представление
-        # return redirect('home') # указываем имя маршрута
-        # return redirect('/', permanent=True) # код 301
-        uri = reverse('cats', args=('sport', ))
-        print(uri)
-        # return redirect(uri)
-        return HttpResponseRedirect('/') 
-    return HttpResponse(f"<h1>Архив по годам</h1><p>{year}</p>")
-
-
-def post_detail(request):
-    if request.GET:
-        ans = ""
-        for key, value in request.GET.items():
-            ans += f'{key}={value}|'
-        return HttpResponse(ans[:-1])
-    else:
-        return HttpResponse("GET is empty")
-
-
-def posts_list(request, year):
-    if 1990 <= year <= 2023:
-        return HttpResponse(f'posts: {year}')
-    else:
-        raise Http404()
-
-
-def page_not_found(request, exception):
+from django.shortcuts import render, redirect
+from django.http import HttpResponse, HttpResponseNotFound, Http404, HttpResponseRedirect
+from django.urls import reverse
+from django.template.loader import render_to_string
+from django.template.defaultfilters import slugify
+
+
+# Create your views here.
+
+menu = [{'title': "О сайте", 'url_name': 'about'},
+        {'title': "Добавить статью", 'url_name': 'add_page'},
+        {'title': "Обатная связь", 'url_name': 'contact'},
+        {'title': "Войти", 'url_name': 'login'}
+]
+
+data_db = [
+    {'id': 1, 'title': 'Анджелина Джоли', 'content': 'Биография Анджелины Джоли', 'is_published': True },
+    {'id': 2, 'title': 'Марго Робби', 'content': 'Биография Марго Робби', 'is_published': False },
+    {'id': 3, 'title': 'Джулия Робертс', 'content': 'Биография Джулия Робертс', 'is_published': True },
+]
+
+
+
+def index(request): # HttRequest
+    # t = render_to_string('women/index.html')
+    # return HttpResponse(t)
+
+    # data = {'title': 'главная страница?',
+    #         'menu': menu,
+    #         'float': 234.465,
+    #         'lst': [1, 2, 'abc', True],
+    #         'set': {1, 2, 3, 4, 5},
+    #         'dict': {'key_1': 'value_1', 'key_2': 'value_2'},
+    #         'obj': MyClass(10, 20),
+    #         'url': slugify("The main page"),
+    # }
+
+    data = {'title': 'Главная страница',
+            'menu': menu,
+            'posts': data_db,
+    }
+    
+
+    return render(request, 'women/index.html', context=data)
+
+
+def about(request):
+    return render(request, 'women/about.html',  {'title': 'О сайте'})
+
+
+def show_post(request, post_id):
+    return HttpResponse(f"Отображение статьи с id = {post_id}")
+
+
+def addpage(request):
+    return HttpResponse("Добавление статьи")
+
+
+def contact(request):
+    return HttpResponse("Обратная связь")
+
+
+def login(request):
+    return HttpResponse("Авторизация")
+
+
+
+
+
+def page_not_found(request, exception):
     return HttpResponseNotFound("<h1>Страница не найдена</h1>")