diff --git a/dongjae/secondSemester-week6_repo/.gitignore b/dongjae/secondSemester-week6_repo/.gitignore new file mode 100644 index 00000000..31c1dd0f --- /dev/null +++ b/dongjae/secondSemester-week6_repo/.gitignore @@ -0,0 +1,273 @@ +# Created by https://www.toptal.com/developers/gitignore/api/python,django +# Edit at https://www.toptal.com/developers/gitignore?templates=python,django + +# Mac +.DS_STORE + +# vscode +.vscode/ + +### Django ### +*.log +*.pot +*.pyc +__pycache__/ +local_settings.py +db.sqlite3 +db.sqlite3-journal +media +secrets.json + +# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/ +# in your Git repository. Update and uncomment the following line accordingly. +# /staticfiles/ + +### Django.Python Stack ### +# Byte-compiled / optimized / DLL files +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo + +# Django stuff: + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +### Python ### +# Byte-compiled / optimized / DLL files + +# C extensions + +# Distribution / packaging + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. + +# Installer logs + +# Unit test / coverage reports + +# Translations + +# Django stuff: + +# Flask stuff: + +# Scrapy stuff: + +# Sphinx documentation + +# PyBuilder + +# Jupyter Notebook + +# IPython + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm + +# Celery stuff + +# SageMath parsed files + +# Environments + +# Spyder project settings + +# Rope project settings + +# mkdocs documentation + +# mypy + +# Pyre type checker + +# pytype static type analyzer + +# Cython debug symbols + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. + +### Python Patch ### +# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration +poetry.toml + +# ruff +.ruff_cache/ + +# LSP config files +pyrightconfig.json + +# End of https://www.toptal.com/developers/gitignore/api/python,django \ No newline at end of file diff --git a/dongjae/secondSemester-week6_repo/README.md b/dongjae/secondSemester-week6_repo/README.md new file mode 100644 index 00000000..dbd5b631 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/README.md @@ -0,0 +1 @@ +# LikeLion_2semester_week6 diff --git a/dongjae/secondSemester-week6_repo/likeapp/__init__.py b/dongjae/secondSemester-week6_repo/likeapp/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/dongjae/secondSemester-week6_repo/likeapp/admin.py b/dongjae/secondSemester-week6_repo/likeapp/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeapp/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/dongjae/secondSemester-week6_repo/likeapp/apps.py b/dongjae/secondSemester-week6_repo/likeapp/apps.py new file mode 100644 index 00000000..0b4a2ecb --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeapp/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class LikeappConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'likeapp' diff --git a/dongjae/secondSemester-week6_repo/likeapp/forms.py b/dongjae/secondSemester-week6_repo/likeapp/forms.py new file mode 100644 index 00000000..0223322f --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeapp/forms.py @@ -0,0 +1,7 @@ +from django import forms +from .models import Blog + +class BlogForm(forms.ModelForm): + class Meta: + model = Blog + fields = ['title', 'body'] \ No newline at end of file diff --git a/dongjae/secondSemester-week6_repo/likeapp/migrations/0001_initial.py b/dongjae/secondSemester-week6_repo/likeapp/migrations/0001_initial.py new file mode 100644 index 00000000..552e22b4 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeapp/migrations/0001_initial.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.6 on 2023-10-27 06:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Blog', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=100)), + ('pub_date', models.DateTimeField(verbose_name='data published')), + ('body', models.TextField()), + ], + ), + ] diff --git a/dongjae/secondSemester-week6_repo/likeapp/migrations/0002_blog_like_user_blog_user.py b/dongjae/secondSemester-week6_repo/likeapp/migrations/0002_blog_like_user_blog_user.py new file mode 100644 index 00000000..719c01ef --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeapp/migrations/0002_blog_like_user_blog_user.py @@ -0,0 +1,26 @@ +# Generated by Django 4.2.7 on 2023-11-03 09:39 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('likeapp', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='blog', + name='like_user', + field=models.ManyToManyField(blank=True, related_name='like_blogs', to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='blog', + name='user', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='blogs', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/dongjae/secondSemester-week6_repo/likeapp/migrations/0003_blog_bookmark_user_alter_blog_like_user_and_more.py b/dongjae/secondSemester-week6_repo/likeapp/migrations/0003_blog_bookmark_user_alter_blog_like_user_and_more.py new file mode 100644 index 00000000..50dcc6c7 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeapp/migrations/0003_blog_bookmark_user_alter_blog_like_user_and_more.py @@ -0,0 +1,31 @@ +# Generated by Django 4.2.7 on 2023-11-08 14:36 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('likeapp', '0002_blog_like_user_blog_user'), + ] + + operations = [ + migrations.AddField( + model_name='blog', + name='bookmark_user', + field=models.ManyToManyField(blank=True, related_name='bookmark_user', to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='blog', + name='like_user', + field=models.ManyToManyField(blank=True, related_name='like_user', to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='blog', + name='user', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='blog', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/dongjae/secondSemester-week6_repo/likeapp/migrations/__init__.py b/dongjae/secondSemester-week6_repo/likeapp/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/dongjae/secondSemester-week6_repo/likeapp/models.py b/dongjae/secondSemester-week6_repo/likeapp/models.py new file mode 100644 index 00000000..bf42ee6c --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeapp/models.py @@ -0,0 +1,14 @@ +from django.db import models +from django.conf import settings +from django.contrib.auth import get_user_model + +# Create your models here. +class Blog(models.Model): + title = models.CharField(max_length=100) + pub_date = models.DateTimeField('data published') + body = models.TextField() + user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='blog', null=True) + like_user = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='like_user', blank=True) + bookmark_user = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='bookmark_user', blank=True) + def __str__(self): + return self.title \ No newline at end of file diff --git a/dongjae/secondSemester-week6_repo/likeapp/templates/create.html b/dongjae/secondSemester-week6_repo/likeapp/templates/create.html new file mode 100644 index 00000000..9af5d2da --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeapp/templates/create.html @@ -0,0 +1,17 @@ +{% extends 'index.html' %} + +{% block title %} + Create +{% endblock %} + +{% block content %} +

Create Page

+
+
+ {% csrf_token %} + + {{form.as_table}} +
+ +
+{% endblock %} \ No newline at end of file diff --git a/dongjae/secondSemester-week6_repo/likeapp/templates/detail.html b/dongjae/secondSemester-week6_repo/likeapp/templates/detail.html new file mode 100644 index 00000000..0c45abbc --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeapp/templates/detail.html @@ -0,0 +1,50 @@ +{% extends 'index.html' %} + +{% block title %} + Detail + + + +{% endblock %} + +{% block content %} +

Detail Page

+
+

{{ blog.title }}

+

{{ blog.pub_date }}

+

{{ blog.body }}

+
+ +
+
+ {% csrf_token %} + + + {{ blog.like_user.all|length}} 명이 이 글을 좋아합니다. + +
+
+ +
+
+ {% csrf_token %} + +
+
+ + 글 수정하기 +
+ 글 삭제하기 +{% endblock %} \ No newline at end of file diff --git a/dongjae/secondSemester-week6_repo/likeapp/templates/index.html b/dongjae/secondSemester-week6_repo/likeapp/templates/index.html new file mode 100644 index 00000000..5ceeab8b --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeapp/templates/index.html @@ -0,0 +1,31 @@ + + + + + + + + {% block title %} + Index + {% endblock %} + + + + {% block content %} +

Index Page

+
+ {% endblock %} + + \ No newline at end of file diff --git a/dongjae/secondSemester-week6_repo/likeapp/templates/mybookmark.html b/dongjae/secondSemester-week6_repo/likeapp/templates/mybookmark.html new file mode 100644 index 00000000..7b4655a4 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeapp/templates/mybookmark.html @@ -0,0 +1,14 @@ +{% extends 'index.html' %} + +{% block content %} +

bookmark Page

+
+ + {% if user.is_active %} +

{{ user.username }}님의 작성글

+ {% for blogs in blogs %} +

{{ blogs.title }}

+
+ {% endfor %} + {% endif %} +{% endblock %} \ No newline at end of file diff --git a/dongjae/secondSemester-week6_repo/likeapp/templates/read.html b/dongjae/secondSemester-week6_repo/likeapp/templates/read.html new file mode 100644 index 00000000..df20ba47 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeapp/templates/read.html @@ -0,0 +1,25 @@ +{% extends 'index.html' %} + +{% block title %} + Read +{% endblock %} + +{% block content %} +

Read Page

+
+ {% for blogs in blogs %} +

{{ blogs.title }}

+

{{ blogs.pub_date }}

+

{{ blogs.body }}

+
+ {% csrf_token %} + +
+ {% endfor %} +{% endblock %} \ No newline at end of file diff --git a/dongjae/secondSemester-week6_repo/likeapp/templates/update.html b/dongjae/secondSemester-week6_repo/likeapp/templates/update.html new file mode 100644 index 00000000..2d8ba2a0 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeapp/templates/update.html @@ -0,0 +1,17 @@ +{% extends 'index.html' %} + +{% block title %} + Update +{% endblock %} + +{% block content %} +

Update Page

+
+
+ {% csrf_token %} + + {{ form.as_table }} +
+ +
+{% endblock %} \ No newline at end of file diff --git a/dongjae/secondSemester-week6_repo/likeapp/tests.py b/dongjae/secondSemester-week6_repo/likeapp/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeapp/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/dongjae/secondSemester-week6_repo/likeapp/urls.py b/dongjae/secondSemester-week6_repo/likeapp/urls.py new file mode 100644 index 00000000..d0acb78f --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeapp/urls.py @@ -0,0 +1,15 @@ +from django.urls import path +from likeapp import views + +urlpatterns = [ + path('', views.index, name='index'), + path('create/', views.create, name='create'), + path('read/', views.read, name = 'read'), + path('detail//', views.detail, name = 'detail'), + path('update//', views.update, name='update'), + path('delete//', views.delete, name = 'delete'), + path('like/', views.like, name='like'), + path('bookmark/', views.bookmark, name='bookmark'), + path('mybookmark/', views.mybookmark, name='mybookmark'), + path('bookmark//', views.bookmark, name='bookmark'), +] \ No newline at end of file diff --git a/dongjae/secondSemester-week6_repo/likeapp/views.py b/dongjae/secondSemester-week6_repo/likeapp/views.py new file mode 100644 index 00000000..05310fa0 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeapp/views.py @@ -0,0 +1,75 @@ +from django.shortcuts import render, redirect, get_object_or_404 +from .forms import BlogForm +from django.utils import timezone +from .models import Blog + +# Create your views here. + +def index(request): + return render(request, 'index.html') + +def create(request): + if request.method == 'POST': + form = BlogForm(request.POST) + if form.is_valid(): + form = form.save(commit=False) + form.pub_date = timezone.now() + form.save() + return redirect('read') + else: + form = BlogForm + return render(request, 'create.html', {'form' : form}) + +def read(request): + blogs = Blog.objects.all() + return render(request, 'read.html', {'blogs' : blogs}) + +def detail(request, id): + blog = get_object_or_404(Blog, id = id) + return render(request, 'detail.html', {'blog' : blog}) + +def update(request, id): + blog = get_object_or_404(Blog, id = id) + if request.method == 'POST': + form = BlogForm(request.POST, instance=blog) + if form.is_valid(): + form = form.save(commit = False) + form.pub_date = timezone.now() + form.save() + return redirect('read') + else: + form = BlogForm(instance=blog) + return render(request, 'update.html', {'form' : form}) + +def delete(request, id): + blog = get_object_or_404(Blog, id = id) + blog.delete() + return redirect('read') + +def like(request, id): + if request.user.is_authenticated: + blog = get_object_or_404(Blog, id = id) + if blog.like_user.filter(id = request.user.id).exists(): + blog.like_user.remove(request.user) + else: + blog.like_user.add(request.user) + return redirect('detail', id=id) + return redirect('login') + + + +def bookmark(request, id): + if request.user.is_authenticated: + blog = get_object_or_404(Blog, id = id) + if blog.bookmark_user.filter(id = request.user.id).exists(): + blog.bookmark_user.remove(request.user) + else: + blog.bookmark_user.add(request.user) + return redirect('detail', id=id) + return redirect('login') + +def mybookmark(request): + if request.user.is_authenticated: + blogs = Blog.objects.filter(bookmark_user=request.user) + return render(request, 'mybookmark.html', {'blogs' : blogs}) + return redirect('login') \ No newline at end of file diff --git a/dongjae/secondSemester-week6_repo/likeprj/__init__.py b/dongjae/secondSemester-week6_repo/likeprj/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/dongjae/secondSemester-week6_repo/likeprj/asgi.py b/dongjae/secondSemester-week6_repo/likeprj/asgi.py new file mode 100644 index 00000000..fcd1ca6c --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeprj/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for likeprj 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.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'likeprj.settings') + +application = get_asgi_application() diff --git a/dongjae/secondSemester-week6_repo/likeprj/settings.py b/dongjae/secondSemester-week6_repo/likeprj/settings.py new file mode 100644 index 00000000..e10dfe41 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeprj/settings.py @@ -0,0 +1,139 @@ +""" +Django settings for likeprj project. + +Generated by 'django-admin startproject' using Django 4.2.6. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" + +from pathlib import Path +import os, json +from django.core.exceptions import ImproperlyConfigured + +# 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.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +secret_file = os.path.join(BASE_DIR, 'secrets.json') + +with open(secret_file) as f: + secrets = json.loads(f.read()) + +def get_secret(setting, secrets = secrets): + try: + return secrets[setting] + except KeyError: + error_msg = "Set the {} enviroment variable".format(setting) + raise ImproperlyConfigured(error_msg) + +SECRET_KEY = get_secret("SECRET_KEY") + +# 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', + 'likeapp.apps.LikeappConfig', + 'userapp', +] + +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 = 'likeprj.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 = 'likeprj.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.2/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.2/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.2/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/dongjae/secondSemester-week6_repo/likeprj/urls.py b/dongjae/secondSemester-week6_repo/likeprj/urls.py new file mode 100644 index 00000000..476ef2d7 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeprj/urls.py @@ -0,0 +1,26 @@ +""" +URL configuration for likeprj project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.2/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, include +import likeapp.views + +urlpatterns = [ + path('admin/', admin.site.urls), + + path('', include('likeapp.urls')), + path('', include('userapp.urls')), +] \ No newline at end of file diff --git a/dongjae/secondSemester-week6_repo/likeprj/wsgi.py b/dongjae/secondSemester-week6_repo/likeprj/wsgi.py new file mode 100644 index 00000000..b94bb08d --- /dev/null +++ b/dongjae/secondSemester-week6_repo/likeprj/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for likeprj 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.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'likeprj.settings') + +application = get_wsgi_application() diff --git a/dongjae/secondSemester-week6_repo/manage.py b/dongjae/secondSemester-week6_repo/manage.py new file mode 100644 index 00000000..aebb9535 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/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', 'likeprj.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/dongjae/secondSemester-week6_repo/userapp/__init__.py b/dongjae/secondSemester-week6_repo/userapp/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/dongjae/secondSemester-week6_repo/userapp/admin.py b/dongjae/secondSemester-week6_repo/userapp/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/userapp/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/dongjae/secondSemester-week6_repo/userapp/apps.py b/dongjae/secondSemester-week6_repo/userapp/apps.py new file mode 100644 index 00000000..2b91b7a2 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/userapp/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class UserappConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'userapp' diff --git a/dongjae/secondSemester-week6_repo/userapp/migrations/__init__.py b/dongjae/secondSemester-week6_repo/userapp/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/dongjae/secondSemester-week6_repo/userapp/models.py b/dongjae/secondSemester-week6_repo/userapp/models.py new file mode 100644 index 00000000..d49766e4 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/userapp/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. \ No newline at end of file diff --git a/dongjae/secondSemester-week6_repo/userapp/templates/login.html b/dongjae/secondSemester-week6_repo/userapp/templates/login.html new file mode 100644 index 00000000..bb6be938 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/userapp/templates/login.html @@ -0,0 +1,17 @@ +{% extends 'index.html' %} + +{% block title %} + Login +{% endblock %} + +{% block content %} +

Login Page

+
+
+ {% csrf_token %} + + {{ form.as_table }} +
+ +
+{% endblock %} \ No newline at end of file diff --git a/dongjae/secondSemester-week6_repo/userapp/templates/signup.html b/dongjae/secondSemester-week6_repo/userapp/templates/signup.html new file mode 100644 index 00000000..6d5a23f7 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/userapp/templates/signup.html @@ -0,0 +1,17 @@ +{% extends 'index.html' %} + +{% block title %} + Signup +{% endblock %} + +{% block content %} +

Signup Page

+
+
+ {% csrf_token %} + + {{ form.as_table }} +
+ +
+{% endblock %} \ No newline at end of file diff --git a/dongjae/secondSemester-week6_repo/userapp/tests.py b/dongjae/secondSemester-week6_repo/userapp/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/userapp/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/dongjae/secondSemester-week6_repo/userapp/urls.py b/dongjae/secondSemester-week6_repo/userapp/urls.py new file mode 100644 index 00000000..2c0a0ee3 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/userapp/urls.py @@ -0,0 +1,8 @@ +from django.urls import path +import userapp.views + +urlpatterns = [ + path('signup/', userapp.views.signup, name = 'signup'), + path('login/', userapp.views.login, name = 'login'), + path('logout/', userapp.views.logout, name = 'logout'), +] diff --git a/dongjae/secondSemester-week6_repo/userapp/views.py b/dongjae/secondSemester-week6_repo/userapp/views.py new file mode 100644 index 00000000..9b7f26c2 --- /dev/null +++ b/dongjae/secondSemester-week6_repo/userapp/views.py @@ -0,0 +1,34 @@ +from django.shortcuts import render, redirect +from django.contrib import auth +from django.contrib.auth.forms import UserCreationForm, AuthenticationForm + +# Create your views here. +def signup(request): + if request.method == 'POST': + form = UserCreationForm(request.POST) + if form.is_valid(): + user = form.save() + auth.login(request, user) # 인증된 사용자를 로그인 처리 + return redirect('index') + else: + return render(request, 'signup.html', {'form': form}) + else: + form = UserCreationForm() + return render(request, 'signup.html', {'form' : form}) + +def login(request): + if request.method == 'POST': + form = AuthenticationForm(data = request.POST) + if form.is_valid(): + user = form.get_user() + auth.login(request, user) + return redirect('index') + else: + return render(request, 'signup.html', {'form': form}) + else: + form = AuthenticationForm() + return render(request, 'login.html', {'form' : form}) + +def logout(request): + auth.logout(request) + return redirect('index') \ No newline at end of file