Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0522] 장고 세션 실습 제출 #40

Open
wants to merge 2 commits into
base: 박규리
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
guestbook division
gyurili committed May 21, 2023
commit 70d0b350a26ebcf42d1db553c6b72e1e856a815c
2 changes: 1 addition & 1 deletion BE_guestBook/BE_guestBook/settings.py
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [BASE_DIR/'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
26 changes: 6 additions & 20 deletions BE_guestBook/BE_guestBook/urls.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
"""
URL configuration for BE_guestBook 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
from django.urls import path, include
from guest_app import views
from guest_app.views import *

urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index, name="index")
]
path('admin/', admin.site.urls),
path('', views.index, name='index'),
path('guestapp/', include('guest_app.urls')),
]
14 changes: 14 additions & 0 deletions BE_guestBook/guest_app/templates/guest_app/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>방명록</title>
</head>
<body>
{% block main %}
{% endblock %}
{% include 'guest_app/footer.html' %}
</body>
</html>
14 changes: 14 additions & 0 deletions BE_guestBook/guest_app/templates/guest_app/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=<device-width>, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div style="border: 2px solid hotpink; margin-top: 50px;">
<h5>이것은 규리가 만든 미니홈피입니다</h5>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -7,13 +7,16 @@
<title>Document</title>
</head>
<body>
{% extends 'guest_app/base.html' %}
{% block main %}
<h1>방명록 목록</h1>
<ul>
{% for book in books %}
{% for book in guestbook_list %}
<li>{{ book.title }} - {{ book.author }} ({{ book.datetime }})</li>
{% empty %}
{% empty %}
<li>방명록이 없습니다.</li>
{%endfor%}
{%endfor%}
</ul>
{% endblock %}
</body>
</html>
17 changes: 17 additions & 0 deletions BE_guestBook/guest_app/templates/guest_app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>환영합니다</h1>
<h2>여기는 아름다운 미니홈피</h2>

<a href="{% url 'guest_app:guestbook-list' %}">방명록 바로가기</a>
{% include 'guest_app/footer.html' %}

</body>
</html>
9 changes: 9 additions & 0 deletions BE_guestBook/guest_app/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path, include
from guest_app import views
from guest_app.views import *

app_name = 'guest_app'

urlpatterns = [
path('', GuestList.as_view(), name='guestbook-list'),
]
10 changes: 9 additions & 1 deletion BE_guestBook/guest_app/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from django.shortcuts import render
from .models import GuestBook
from django.views.generic import ListView

# Create your views here.
def index(request):
books = GuestBook.objects.all()
return render(request, "index.html", {'books' : books})
return render(request, "index.html", {'books' : books})

class GuestList(ListView):
model = GuestBook
ordering = ['-datetime']

def index(request):
return render(request, "guest_app/index.html")