본문 바로가기

Django 맛보기

Django 맛보기7 - 테스트 안녕하세요. 상당히 오랜만에 돌아온 개발자 정씨입니다. 그럼 오늘도 여김없이 바로 시작해보도록 하죠 1. 테스트 오류검증은 어느 프로그래밍에서든 중요한 부분이라고 생각합니다. Django에서는 어떤방식으로 오류를 검증할 수 있는지 확인해보도록 하겠습니다. # polls/models.py class Question(models.Model): question_text = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __str__(self): return self.question_text def was_published_recently(self): return self.pub_date >= timez.. 더보기
Django 맛보기6 - 심화된 뷰(View) 만들기 안녕하세요 개발자정씨입니다. 꽤 오랫만에 돌아온것 같네요 언능 시작해보죠 1. 투표 form 만들기 # polls/templates/polls/detail.html {% csrf_token %} {{ question.question_text }} {% if error_message %}{{ error_message }}{% endif %} {% for choice in question.choice_set.all %} {{ choice.choice_text }} {% endfor %} polls/templates/polls/detail.html를 위와 같이 수정하여 form을 만들어주고 # polls/views.py from django.http import HttpResponse, HttpResponse.. 더보기
Django 맛보기5 - 뷰 만들기 안녕하세요 개발자 정씨입니다. 꽤 많이 했다고 생각했는데, 아직 갈길이 멀군요. 더 열심히 해봐야겠습니다. 1. 뷰(View) 추가하기 # polls/views.py def detail(request, question_id): return HttpResponse("You're looking at question %s." % question_id) def results(request, question_id): response = "You're looking at the results of question %s." return HttpResponse(response % question_id) def vote(request, question_id): return HttpResponse("You're votin.. 더보기
Django 맛보기4 - 관리자 생성하기 안녕하세요 개발자 정씨입니다. 앞서 개요 부분에서도 말씀드렸다시피 저는 "https://docs.djangoproject.com/ko/3.2"를 참조하고 있습니다. 저번시간에 DB설치 및 모델링 작업을 진행했었는데, Document기준 "API 가지고 놀기"는 생략하겠습니다. 해당 부분에서도 수정되는 부분이 조금 있으니 참고 부탁드립니다. 1. 관리자 생성하기 python manage.py createsuperuser >> Username: admin >> Email address: admin@example.com >> Password: ********** >> Password (again): ********* >> Superuser created successfully. 명령어를 입력하고 위의 과정들을.. 더보기