From dfd461d45cd33148455f0b09fee563f36b551a4e Mon Sep 17 00:00:00 2001 From: hayrin0603 Date: Sat, 11 Nov 2023 22:19:15 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B6=81=EB=A7=88=ED=81=AC=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 273 ++++++++++++++++++ README.md | 1 + likeapp/__init__.py | 0 likeapp/admin.py | 3 + likeapp/apps.py | 6 + likeapp/forms.py | 7 + likeapp/migrations/0001_initial.py | 23 ++ .../0002_blog_like_user_blog_user.py | 26 ++ likeapp/migrations/0003_wishlist.py | 24 ++ ...0004_blog_bookmark_user_delete_wishlist.py | 23 ++ likeapp/migrations/__init__.py | 0 likeapp/models.py | 15 + likeapp/templates/create.html | 20 ++ likeapp/templates/detail.html | 55 ++++ likeapp/templates/index.html | 28 ++ likeapp/templates/mybookmark.html | 13 + likeapp/templates/read.html | 30 ++ likeapp/templates/update.html | 17 ++ likeapp/tests.py | 3 + likeapp/urls.py | 15 + likeapp/views.py | 73 +++++ likeprj/__init__.py | 0 likeprj/asgi.py | 16 + likeprj/settings.py | 139 +++++++++ likeprj/urls.py | 23 ++ likeprj/wsgi.py | 16 + manage.py | 22 ++ userapp/__init__.py | 0 userapp/admin.py | 3 + userapp/apps.py | 6 + userapp/migrations/__init__.py | 0 userapp/models.py | 3 + userapp/templates/login.html | 17 ++ userapp/templates/signup.html | 17 ++ userapp/tests.py | 3 + userapp/urls.py | 8 + userapp/views.py | 34 +++ 37 files changed, 962 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 likeapp/__init__.py create mode 100644 likeapp/admin.py create mode 100644 likeapp/apps.py create mode 100644 likeapp/forms.py create mode 100644 likeapp/migrations/0001_initial.py create mode 100644 likeapp/migrations/0002_blog_like_user_blog_user.py create mode 100644 likeapp/migrations/0003_wishlist.py create mode 100644 likeapp/migrations/0004_blog_bookmark_user_delete_wishlist.py create mode 100644 likeapp/migrations/__init__.py create mode 100644 likeapp/models.py create mode 100644 likeapp/templates/create.html create mode 100644 likeapp/templates/detail.html create mode 100644 likeapp/templates/index.html create mode 100644 likeapp/templates/mybookmark.html create mode 100644 likeapp/templates/read.html create mode 100644 likeapp/templates/update.html create mode 100644 likeapp/tests.py create mode 100644 likeapp/urls.py create mode 100644 likeapp/views.py create mode 100644 likeprj/__init__.py create mode 100644 likeprj/asgi.py create mode 100644 likeprj/settings.py create mode 100644 likeprj/urls.py create mode 100644 likeprj/wsgi.py create mode 100644 manage.py create mode 100644 userapp/__init__.py create mode 100644 userapp/admin.py create mode 100644 userapp/apps.py create mode 100644 userapp/migrations/__init__.py create mode 100644 userapp/models.py create mode 100644 userapp/templates/login.html create mode 100644 userapp/templates/signup.html create mode 100644 userapp/tests.py create mode 100644 userapp/urls.py create mode 100644 userapp/views.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..31c1dd0f --- /dev/null +++ b/.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/README.md b/README.md new file mode 100644 index 00000000..dbd5b631 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# LikeLion_2semester_week6 diff --git a/likeapp/__init__.py b/likeapp/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/likeapp/admin.py b/likeapp/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/likeapp/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/likeapp/apps.py b/likeapp/apps.py new file mode 100644 index 00000000..0b4a2ecb --- /dev/null +++ b/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/likeapp/forms.py b/likeapp/forms.py new file mode 100644 index 00000000..0223322f --- /dev/null +++ b/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/likeapp/migrations/0001_initial.py b/likeapp/migrations/0001_initial.py new file mode 100644 index 00000000..552e22b4 --- /dev/null +++ b/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/likeapp/migrations/0002_blog_like_user_blog_user.py b/likeapp/migrations/0002_blog_like_user_blog_user.py new file mode 100644 index 00000000..a23d4b28 --- /dev/null +++ b/likeapp/migrations/0002_blog_like_user_blog_user.py @@ -0,0 +1,26 @@ +# Generated by Django 4.2.1 on 2023-11-03 09:43 + +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/likeapp/migrations/0003_wishlist.py b/likeapp/migrations/0003_wishlist.py new file mode 100644 index 00000000..7af8807d --- /dev/null +++ b/likeapp/migrations/0003_wishlist.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.7 on 2023-11-10 13:52 + +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.CreateModel( + name='Wishlist', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='wishlists', to='likeapp.blog')), + ('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='wishlists', to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/likeapp/migrations/0004_blog_bookmark_user_delete_wishlist.py b/likeapp/migrations/0004_blog_bookmark_user_delete_wishlist.py new file mode 100644 index 00000000..2ba0a5e9 --- /dev/null +++ b/likeapp/migrations/0004_blog_bookmark_user_delete_wishlist.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.7 on 2023-11-11 12:56 + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('likeapp', '0003_wishlist'), + ] + + operations = [ + migrations.AddField( + model_name='blog', + name='bookmark_user', + field=models.ManyToManyField(blank=True, related_name='bookmark_user', to=settings.AUTH_USER_MODEL), + ), + migrations.DeleteModel( + name='Wishlist', + ), + ] diff --git a/likeapp/migrations/__init__.py b/likeapp/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/likeapp/models.py b/likeapp/models.py new file mode 100644 index 00000000..18af2ee2 --- /dev/null +++ b/likeapp/models.py @@ -0,0 +1,15 @@ +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(get_user_model(), on_delete=models.CASCADE, null=True, related_name='blogs') + like_user = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True, related_name='like_blogs') + bookmark_user = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True, related_name='bookmark_user') + + def __str__(self): + return self.title \ No newline at end of file diff --git a/likeapp/templates/create.html b/likeapp/templates/create.html new file mode 100644 index 00000000..71ce9939 --- /dev/null +++ b/likeapp/templates/create.html @@ -0,0 +1,20 @@ +{% 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/likeapp/templates/detail.html b/likeapp/templates/detail.html new file mode 100644 index 00000000..5d76700b --- /dev/null +++ b/likeapp/templates/detail.html @@ -0,0 +1,55 @@ +{% 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 %} + + + {{ blog.bookmark_user.all|length}}명이 이 글을 북마크 했습니다. + +
+
+ + 글 수정하기 +
+ 글 삭제하기 +{% endblock %} \ No newline at end of file diff --git a/likeapp/templates/index.html b/likeapp/templates/index.html new file mode 100644 index 00000000..74440426 --- /dev/null +++ b/likeapp/templates/index.html @@ -0,0 +1,28 @@ + + + + + + + {% block title %} + Index + {% endblock %} + + + + {% block content %} +

Index Page

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

bookmark Page

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

북마크 목록

+{% for blogs in blogs %} +

{{ blogs.title }}

+{% endfor %} +{% endif %} +{% endblock %} \ No newline at end of file diff --git a/likeapp/templates/read.html b/likeapp/templates/read.html new file mode 100644 index 00000000..7104a9c5 --- /dev/null +++ b/likeapp/templates/read.html @@ -0,0 +1,30 @@ +{% 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/likeapp/templates/update.html b/likeapp/templates/update.html new file mode 100644 index 00000000..2d8ba2a0 --- /dev/null +++ b/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/likeapp/tests.py b/likeapp/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/likeapp/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/likeapp/urls.py b/likeapp/urls.py new file mode 100644 index 00000000..b05b8864 --- /dev/null +++ b/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('mybookmark/', views.mybookmark, name='mybookmark'), + 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'), +] \ No newline at end of file diff --git a/likeapp/views.py b/likeapp/views.py new file mode 100644 index 00000000..264182f9 --- /dev/null +++ b/likeapp/views.py @@ -0,0 +1,73 @@ +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/likeprj/__init__.py b/likeprj/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/likeprj/asgi.py b/likeprj/asgi.py new file mode 100644 index 00000000..fcd1ca6c --- /dev/null +++ b/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/likeprj/settings.py b/likeprj/settings.py new file mode 100644 index 00000000..e10dfe41 --- /dev/null +++ b/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/likeprj/urls.py b/likeprj/urls.py new file mode 100644 index 00000000..2eba8afb --- /dev/null +++ b/likeprj/urls.py @@ -0,0 +1,23 @@ +""" +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 + +urlpatterns = [ + path('admin/', admin.site.urls), + path('',include('likeapp.urls')), + path('',include('userapp.urls')) +] \ No newline at end of file diff --git a/likeprj/wsgi.py b/likeprj/wsgi.py new file mode 100644 index 00000000..b94bb08d --- /dev/null +++ b/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/manage.py b/manage.py new file mode 100644 index 00000000..aebb9535 --- /dev/null +++ b/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/userapp/__init__.py b/userapp/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/userapp/admin.py b/userapp/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/userapp/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/userapp/apps.py b/userapp/apps.py new file mode 100644 index 00000000..2b91b7a2 --- /dev/null +++ b/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/userapp/migrations/__init__.py b/userapp/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/userapp/models.py b/userapp/models.py new file mode 100644 index 00000000..d49766e4 --- /dev/null +++ b/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/userapp/templates/login.html b/userapp/templates/login.html new file mode 100644 index 00000000..bb6be938 --- /dev/null +++ b/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/userapp/templates/signup.html b/userapp/templates/signup.html new file mode 100644 index 00000000..6d5a23f7 --- /dev/null +++ b/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/userapp/tests.py b/userapp/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/userapp/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/userapp/urls.py b/userapp/urls.py new file mode 100644 index 00000000..2c0a0ee3 --- /dev/null +++ b/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/userapp/views.py b/userapp/views.py new file mode 100644 index 00000000..9b7f26c2 --- /dev/null +++ b/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