728x90
반응형
월요일[파일명을 유의하자..!]
오늘은 미니프로젝트때문에 웹디공부를 하지 못했다..ㅜㅎㅎ헤헤 이거 참 큰일이고만 기래
(+코로나 무서워...
{% load static %} <!doctype html> <html lang="ko"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap CSS --> <link rel="stylesheet" type="text/css" href="{% static 'bootstrap.min.css' %}"> <!-- pybo CSS --> <link rel="stylesheet" type="text/css" href="{% static 'style.css' %}"> <title>Hello, pybo!</title> </head> <body> <!-- 기본 템플릿 안에 삽입될 내용 Start --> {% block content %} {% endblock %} <!-- 기본 템플릿 안에 삽입될 내용 End --> </body> |
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> {% extends 'base.html' %} {% block content %} <div class="container my-3"> <table class="table"> <thead> <tr class="thead-dark"> <th>번호</th> <th>제목</th> <th>작성일시</th> </tr> </thead> <tbody> {% if question_list %} {% for question in question_list %} <tr> <td>{{ forloop.counter }}</td> <td> <a href="{% url 'pybo:detail' question.id %}">{{ question.subject }}</a> </td> <td>{{ question.create_date }}</td> </tr> {% endfor %} {% else %} <tr> <td colspan="3">질문이 없습니다.</td> </tr> {% endif %} </tbody> </table> <a href="{% url 'pybo:question_create' %}" class="btn btn-primary">질문 등록하기</a> </div> {% endblock %} {% if question_list %} <ul> {% for question in question_list %} <li><a href="{% url 'pybo:detail' question.id %}">{{ question.subject }}</a></li> {% endfor %} </ul> {% else %} <p>질문이 없습니다.</p> {% endif %} </body> </html> |
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> {% extends 'base.html' %} {% block content %} <div class="container"> <h5 class="my-3 border-bottom pb-2">질문등록</h5> <form method="post" class="post-form my-3"> {% csrf_token %} <!-- 오류표시 Start --> {% if form.errors %} <div class="alert alert-danger" role="alert"> {% for field in form %} {% if field.errors %} <strong>{{ field.label }}</strong> {{ field.errors }} {% endif %} {% endfor %} </div> {% endif %} <!-- 오류표시 End --> <div class="form-group"> <label for="subject">제목</label> <input type="text" class="form-control" name="subject" id="subject" value="{{ form.subject.value|default_if_none:'' }}"> </div> <div class="form-group"> <label for="content">내용</label> <textarea class="form-control" name="content" id="content" rows="10">{{ form.content.value|default_if_none:'' }}</textarea> </div> <button type="submit" class="btn btn-primary">저장하기</button> </form> </div> {% endblock %} </body> </html> |
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> {% extends 'base.html' %} {% block content %} <div class="container my-3"> <h2 class="border-bottom py-2">{{ question.subject }}</h2> <div class="card my-3"> <div class="card-body"> <div class="card-text" style="white-space: pre-line;">{{ question.content }}</div> <div class="d-flex justify-content-end"> <div class="badge badge-light p-2"> {{ question.create_date }} </div> </div> </div> </div> <h5 class="border-bottom my-3 py-2">{{question.answer_set.count}}개의 답변이 있습니다.</h5> {% for answer in question.answer_set.all %} <div class="card my-3"> <div class="card-body"> <div class="card-text" style="white-space: pre-line;">{{ answer.content }}</div> <div class="d-flex justify-content-end"> <div class="badge badge-light p-2"> {{ answer.create_date }} </div> </div> </div> </div> {% endfor %} <form action="{% url 'pybo:answer_create' question.id %}" method="post" class="my-3"> {% csrf_token %} {% if form.errors %} <div class="alert alert-danger" role="alert"> {% for field in form %} {% if field.errors %} <strong>{{ field.label }}</strong> {{ field.errors }} {% endif %} {% endfor %} </div> {% endif %} <div class="form-group"> <textarea name="content" id="content" class="form-control" rows="10"></textarea> </div> <input type="submit" value="답변등록" class="btn btn-primary"> </form> </div> {% endblock %} </body> </html> |
from django.urls import path from . import views app_name = 'pybo' urlpatterns = [ path('', views.index, name='index'), path('<int:question_id>/', views.detail, name='detail'), path('answer/create/<int:question_id>/', views.answer_create, name='answer_create'), path('question/create/', views.question_create, name='question_create'), ] |
from django.db import models # Create your models here. class Question(models.Model): subject = models.CharField(max_length=200) content = models.TextField() create_date = models.DateTimeField() def __str__(self): return self.subject class Answer(models.Model): question = models.ForeignKey(Question, on_delete=models.CASCADE) content = models.TextField() create_date = models.DateTimeField() |
from django import forms from pybo.models import Question,Answer class QuestionForm(forms.ModelForm): class Meta: model = Question fields = ['subject', 'content'] # widgets = { # 'subject': forms.TextInput(attrs={'class': 'form-control'}), # 'content': forms.Textarea(attrs={'class': 'form-control', 'rows':10}), # } labels = { 'subject': '제목', 'content': '내용', } class AnswerForm(forms.ModelForm): class Meta: model = Answer fields = ['content'] labels = { 'content': '답변내용', } |
from django.http import HttpResponseRedirect from django.shortcuts import render, get_object_or_404, redirect from django.template import RequestContext from django.utils import timezone from .models import Question from .forms import QuestionForm, AnswerForm from django.views.decorators.http import require_http_methods, require_POST, require_GET from django.http import HttpResponse def index(request): """ pybo 목록 출력 """ question_list = Question.objects.order_by('-create_date') context = {'question_list' : question_list} return render(request, 'pybo/question_list.html', context) def detail(request, question_id): """ pybo 내용 출력 """ question = get_object_or_404(Question, pk=question_id) context = {'question': question} return render(request, 'pybo/question_detail.html', context) def question_create(request): """ pybo 질문 등록 """ if request.method == 'POST': form = QuestionForm(request.POST) if form.is_valid(): question = form.save(commit=False) question.create_date = timezone.now() question.save() return redirect('pybo:index') else: form = QuestionForm() context = {'form': form} return render(request, 'pybo/question_form.html', context) def answer_create(request, question_id): """ pybo 답변 등록 """ question = get_object_or_404(Question, pk=question_id) if request.method == 'POST': form = AnswerForm(request.POST) if form.is_valid(): answer = form.save(commit=False) answer.create_date = timezone.now() answer.question = question answer.save() return redirect('pybo:index') else: form = AnswerForm() context = {'question': question, 'form': form} return render(request, 'pybo/question_detail.html', context) |
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> {% extends 'base.html' %} {% block content %} <div class="container"> <h5 class="my-3 border-bottom pb-2">질문등록</h5> <form method="post" class="post-form my-3"> {% csrf_token %} <!-- 오류표시 Start --> {% if form.errors %} <div class="alert alert-danger" role="alert"> {% for field in form %} {% if field.errors %} <strong>{{ field.label }}</strong> {{ field.errors }} {% endif %} {% endfor %} </div> {% endif %} <!-- 오류표시 End --> <div class="form-group"> <label for="subject">제목</label> <input type="text" class="form-control" name="subject" id="subject" value="{{ form.subject.value|default_if_none:'' }}"> </div> <div class="form-group"> <label for="content">내용</label> <textarea class="form-control" name="content" id="content" rows="10">{{ form.content.value|default_if_none:'' }}</textarea> </div> <button type="submit" class="btn btn-primary">저장하기</button> </form> </div> {% endblock %} </body> </html> |
자세한 내용은 하률 깃허브를 참고해주세요.
//yesterday wished to today list
. 미니프로젝트 프론트단 다 만들기 _React에서 pycham으로 변경되어서 못함.
. 의욕 떨어지지 않기 ✔
. 좋은 마음으로 한주 보내기 _14.28571428571429%
tomorrow wish list
. 좋은 마음으로 한주 보내기
. 의욕 충만하기
. 나 하나로 충분하기
728x90
반응형
'IT To do and To was' 카테고리의 다른 글
22년 3월 16일_잠을 거의 못 잔날,, 노래는 왜 부른 거야 이 놈... (0) | 2022.03.16 |
---|---|
22년 3월 15일_미니프로젝트 하느라 정신이 없다.. (0) | 2022.03.15 |
22년 3월 13일_brackets popup 넣기, React 강의 및 이미지 넣기 (0) | 2022.03.13 |
22년 3월 12일_긍정적으로 생각하고 자주 놀자, react에 html 순수 파일 적용, brackets page develop(js까지) (0) | 2022.03.12 |
22년 3월 11일_miniproject 2days, brackets new page create (0) | 2022.03.11 |