목록Web (152)
알쓸전컴(알아두면 쓸모있는 전자 컴퓨터)
HTML JavaScript 기본형 test1.html 위와 같은 코드를 입력하면 document.getElementById('hw') 부분에서 보듯이 태그중 id가 hw인 객체를 가져와서 addEventListener 함수를 통해 click 시 함수를 등록 시켜 줍니다. 이러한 부분들이 웹브라우저의 java script API를 사용한 부분입니다. 이러한 부분이 java script 보통의 언어강의에 없는것은 웹브라우저의 API 이지 언어를 설명하는 부분이 아니기 때문입니다. HTML JavaScript 파일로 나누기test1.html script2.js var hw = document.getElementById('hw'); hw.addEventListener('click',function(){ ale..
웹브라우저 객체에 대한 강의는 생활 코딩의 강좌를 따라하며 학습을 목적으로 해당글을 작성 합니다. 작성을 하는 이유는 학습 목적이자 . 다른 기술들의 융합 하면서 같이 공유 하기 위해서 입니다. 생활 코딩 강좌의 좀더 추가적인 자료를 더해 강의의 이해를 조금더 돕기위한 참조용으로 사용하시면 좋을듯 합니다. 원체 생활 코딩 강좌가 초보에게 이해가 쉽도록 잘되있기 때문에 강좌를 본격적으로 들의실 분들은 아래 사이트를 들어가 보시면 도움이 많을듯합니다. 참고 사이트 : https://opentutorials.org/course/1375/6622
css 적용 Django 에서는 css 파일을 static 요소 라고 합니다. Django 에서는 setting.py -> STATICFILES_FINDERS 에 따라 static 파일을 만드는 경로에 규칙이 존재합니다. 지금까지 만들어 왔던 polls/ 에 static 폴더를 만들어 줍니다. 그밑에 다시 polls 폴더를 만들어 주고 style.css 라고 파일을 만들어 줍니다. polls/static/polls/style.cssli a { color: green;} 이후에 $ python manage.py collectstatic 실행 시켜 줍니다. 이렇게 되면 mysite/setting.py STATIC_URL = '/static/'STATIC_ROOT = os.path.join(BASE_DIR, ..
TEST 하기 여기서 테스트 할것은 polls/model.py 의 Question 의 함수에서 was_published_recently()가 Question.pub_date 가 오늘 날짜인지 구분하는 함수를 만들것 입니다. 테스트를 위해 일부러 잘못된 코드를 작성 하도록 할것 입니다. polls/models.py from django.db import models import datetime from django.utils import timezone # Create your models here. class Question(models.Model): question_text = models.CharField(max_length=200) pub_date = models.DateTimeField('date..
제너릭 뷰 URL에서 전달 된 매개 변수에 따라 데이터베이스에서 데이터를 가져 오고 이것을 view에서 rander 함수 등을 통해 템플릿에 리턴하는 기본 웹 개발의 일반적인 경우를 자주 사용하게 되면서 django 에서는 더욱더 적은 코드로 사용할수 있도록 제너릭 뷰라는 것을 제공합니다. 대표적인 제너릭 뷰에서 generic.ListView 와 generic.DetailView 가 있습니다. 먼저 views.py를 먼저 보겠습니다. polls/views.py from django.shortcuts import get_object_or_404, render # Create your views here. from django.http import HttpResponseRedirect,HttpResponse..
HttpResponseRedirect 현재 App에서 다른 App 으로 이동을 해주는 url Redirect 을 해준다. 이전 강의에서 이어 가도록 하겠습니다. polls/views.py from django.shortcuts import get_object_or_404, render # Create your views here. from django.http import HttpResponseRedirect,HttpResponse from .models import Question,Choice from django.urls import reverse def index(request): latest_question_list = Question.objects.order_by('-pub_date')[:5] ..
django 간단한 폼 만들기 일단 예제 코드를 본다음 1개씩 분석을 해보도록 한다. 예제에 앞서 polls/views.py 을 보겠다 polls/views.py from django.shortcuts import get_object_or_404, render # Create your views here. from django.http import HttpResponse from .models import Question def index(request): latest_question_list = Question.objects.order_by('-pub_date')[:5] context = {'latest_question_list': latest_question_list} return render(req..
Template 에서 하드코딩된 URL 을 제거 코딩을 하다보면 템플릿에 아래와 같은 코드를 사용했을때에 {{ question.question_text }} /polls/ 의 url 경로가 바뀌면 /polls/ 의 경로가 들어간 템플릿을 모두 찾아 url 변경을 해줘야 합니다. 적을때는 문제가 안되지만 프로젝트 규모가 커지고 소스 량이 많아질때는 대단히 공수가 많이 들어가는 작업 입니다. 그래서 {{ question.question_text }} 이런식으로 바꿔 쓸수가 있습니다. url 'detail' 은 polls/urls.py from django.conf.urls import url from . import views urlpatterns = [ url(r'^$', views.index, name=..
Template 시스템 사용하기 poll 어플리케이션의 detail() view 로 되돌아 가봅시다. context 변수 question 이 주어졌을때, polls/detail.html 라는 template 을 만들고 어떻게 보이는지 테스트 해보도록 하겠습니다. polls/templates/polls/detail.html{{ question.question_text }} {% for choice in question.choice_set.all %} {{ choice.choice_text }} {% endfor %} 일단 이렇게 적어 줍니다. 데이터를 따라 가보겠습니다. question.question_text 은 polls/views.py from django.shortcuts import get_obj..
django 404 에러 일으키기 polls/views.py from django.shortcuts import render # Create your views here. from django.http import HttpResponse from .models import Question from django.template import loader from django.http import Http404 def detail(request,question_id): try: question = Question.objects.get(pk=question_id) except Question.DoesNotExist: raise Http404("Question does not exist") return rende..