본문 바로가기

lang/Django5

Django 앱 작성하기 part5 [test] Test 장고는 버그 테스트를 자동으로 해준다. 테스트를 통해 디버깅 시간을 절약할 수 있다. 앞으로의 문제를 예방한다. 신뢰도가 증가한다. 협업 시 일을 돕는 효율적인 툴이 된다. 버그 케이스 만들기 $ python manage.py shell >>> import datetime >>> from django.utils import timezone >>> from polls.models import Question >>> # create a Question instance with pub_date 30 days in the future >>> future_question = Question(pub_date=timezone.now() + datetime.timedelta(days=30)) >>> # was.. 2019. 7. 12.
Pycharm 단축키 필요 노트북을 사용하다보면, 작은 화면에 모든 것이 보이지 않아서 필요없는 화면은 끌 필요가 있습니다. 이 때 필요한 것이 창 닫는 단축키 인데요. Pycharm 단축키를 소개합니다. 단축키 내용 Alt + 1 프로젝트창 닫기(열기) Alt + 2 Favorite창 닫기(열기) ... Alt + num 이런식으로 숫자가 붙은 창을 열고 닫을 때 응용하시면 됩니다. Alt + F12 터미널 창 닫기(열기) 2019. 7. 12.
Django 앱 작성하기 part4 [form] 투표(vote) 양식 만들기 반영사항- POST 데이터를 처리한 후에는 항상 HttpResponseRedirect를 반환해야 한다. polls/views.py from django.shortcuts import get_object_or_404, render def results(request, question_id): question = get_object_or_404(Question, pk=question_id) return render(request, 'polls/results.html', {'question': question}) polls/templates/polls/results.html {{ question.question_text }} {% for choice in question.choic.. 2019. 7. 12.
Django 앱 작성하기 part3 [view] view view를 사용하여 만들 것 4가지 색인 페이지 (index) - 최근 질문들 표시 세부 페이지 (detail) 결과 페이지 (results) 투표 기능 (vote) Django는 URL을 조사하여 화면에 보이게 될 view를 선택한다. - URLconfs 사용 또한 뷰는 PDF 생성이나 XML 출력, 실시간으로 ZIP파일을 만들 수 있다. Django는 페이지의 정보가 담긴 HttpResponse 객체를 반환하거나, 예외를 발생시킨다. Template namespacing 뷰에서 사용할 수 있는 템플릿을 작성하여 python 코드로 부터 디자인 영역을 분리한다! Django에게 정확한 템플릿을 지정해주기 위하여 이름공간(namespacing)으로 구분짓는다. polls/templates/pol.. 2019. 7. 12.
Django 앱 작성하기 part2 [model] 모델 설문조사 앱 (poll)을 만들기 위해서 데이터베이스를 구성한다. models.py 를 작성한다. poll/models.py from django.db import models class Question(models.Model): question\_text = models.CharField(max\_length=200) pub\_date = models.DateTimeField('date published') class Choice(models.Model): question = models.ForeignKey(Question, on\_delete=models.CASCADE) choice\_text = models.CharField(max\_length=200) votes = model.. 2019. 7. 11.
728x90