Django

    [pinterest clone (13)] CreateView를 통한 회원가입 구현

    duckracoon.tistory.com/44?category=1017083 Django가 CRUD로 유명한 이유 CRUD는 Create, Read, Update, Delete가 가능한 시스템을 이야기한다. 그리고 Django는 CRUD를 만드는데 있어 생산성이 탁월한 것으로 유명하다. 왜일까? Django는 CRUD에 View를 따로 제공한다. Create view, Rea.. duckracoon.tistory.com Class Based View에 대해 이해하자. views.py class AccountCreateView(CreateView): model = User form_class = UserCreationForm success_url = reverse_lazy('accountapp:hello_..

    Django가 CRUD로 유명한 이유

    CRUD는 Create, Read, Update, Delete가 가능한 시스템을 이야기한다. 그리고 Django는 CRUD를 만드는데 있어 생산성이 탁월한 것으로 유명하다. 왜일까? Django는 CRUD에 View를 따로 제공한다. Create view, Read view, Update view, Delete view. 즉 이 4가지의 작업들을 쉽게 할 수 있는 클래스를 제공해준다. 각 작업에 최적화된 도구를 쥐어준다는 이야기다. 이것을 Class Based View라고 한다. 여기에 반대되는 말도 있다. Function Based View인데 함수 기반의 뷰를 이야기한다.

    [pinterest clone (12)] DB 정보 접근

    duckracoon.tistory.com/41 [pinterest clone (11)] POST 통신을 이용한 DB 데이터 저장 1. Send POST data 2. Receive POST data 3. Save DB 1 hello_world.html {% extends 'base.html' %} {% block content %} Hello World List {% csrf_token %} {{ text }} {% endblock %} hello_world_input 받아.. duckracoon.tistory.com 앞서 만들면서 생기는 객체들이 db에 계속 쌓일텐데 그걸 모두 긁어와서 display하는 과정을 알아보자. views.py from django.shortcuts import render ..

    [pinterest clone (11)] POST 통신을 이용한 DB 데이터 저장

    1. Send POST data 2. Receive POST data 3. Save DB 1 hello_world.html {% extends 'base.html' %} {% block content %} Hello World List {% csrf_token %} {{ text }} {% endblock %} hello_world_input 받아서 text에 넣고 출력하기 views.py from django.http import HttpResponse from django.shortcuts import render def hello_world(request): if request.method == "POST": temp = request.POST.get('hello_world_input') retur..

    [pinterest clone (8)] static 설정과 css분리

    static file 이란? duckracoon.tistory.com/11 [Django Tutorial] Blog 만들기 (10) Vue-Django 연동원리 웹 프로그램에서 css나 img, js 파일들은 static file 혹은 assets file 이라고 한다. django 측면에서 static 파일은 지칭하는 url로 보통 /static/ 이라는 url을 사용한다. /static/이라는.. duckracoon.tistory.com 1 settings.py에 STATIC_ROOT 정의 STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') python manage.py collectstatic 이라는 명령어가 있다. 모든 static 파일들을 한군데로 모아주..

    [pinterest clone (6)] html (include / extends)

    base.html 에서 head를 잘라내고 templates/head.html을 새로 만들었다. head.html base.html {% include 'head.html' %} 1 2 3 {% include 'head.html' %} 이게 include 구문이다. 이런식이면 vue의 component랑 비스무리?하게 쓸 수 있을거 같다. runserver에서 봐도 잘 나타난다. 1 header랑 footer는 계속 재활용할거니까 include로 빼주자. : header.html, footer.html 만들어빼고 include로 넣어주기 {% include 'head.html' %} {% include 'header.html' %} {% include 'footer.html' %} 2 header, fo..

    [pinterest clone (5)] Django template과 Views 연결

    extends / include 잘 모르겠는데 뭔가 extends로 바탕을 만들고 include로 내용을 채워넣는 느낌인거 같다. 그렇게 해서 이제 양쪽에 extends와 include를 모두 포함한 결과물이 요청을 받았을때 되돌려줄 response view가 된다. 우선 만들어본다. 1. platypus/templates 폴더 만들기 2. 밑에 루트가될 base.html 만든다. * base가 templates 안에 있으므로써 accountapp에서 view.py에서 응답을 해줄때 여기서 template을 가져와서 그 안에 내용을 박아넣을 수 있는 형태로 쓸 수 있다. 3. views.py from django.http import HttpResponse from django.shortcuts impo..

    [pinterest clone (3)] Accountapp

    1. python manage.py startapp accountapp (account보다 accountapp 이런식으로 이름 정확히붙이는거 좀 괜찮은 방식인거같음. 앞으로 이렇게 굳혀야겠다) 2. platypus/settings.py에 accountapp을 INSTALLED_APPS에 추가 3. 브라우저에서 어떤 경로로 접속하게 되면 그 경로에서 헬로월드 같은 기본 출력해주는 view만들어보자 from django.http import HttpResponse def hello_world(request): return HttpResponse('Hello world!') request 넣으면 주소로 헬로월드 돌려주고 끝! 4. 라우팅 만든 뷰를 보기 위해서는 뷰로 연결을 시켜주는게 필요하다. -> 라우팅 ..

    [pinterest clone (2)] Pycharm setup

    duckracoon.tistory.com/2 django 설치와 더불어 참고. [Django Tutorial] Blog 만들기 (1) Django skeleton 만들기 MVT 순서에 따라서 settings.py, (M) models.py, urls.py, (V) views.py, (T) templates 를 만든다. (1) Pycharm에 django 설치 File > settings > project: backend > python interpreter.. duckracoon.tistory.com 1. platypus project를 만들었다., (* 가상환경 추가할것) 2. django 설치 : pip install django * pip list 로 설치된 라이브러리를 확인할 수 있다. * dja..

    [Django Tutorial] Blog 만들기 (18)

    Vue-Django Read API axios list Srialize api/views_util.py 를 만들어 obj_to_post() 메서드를 정의해준다. def obj_to_post(obj): post=dict(vars(obj)) # convert to string return post obj를 dictionary로 바꿔주고 post dictionary에 있는 내용을 string으로 바꿔준 다음에 최종 딕셔너리 타입은 post를 리턴해준다. json 타입을 serialize 한다는 의미를 간단하게 얘기하면 파이썬의 객체를 string의 형태로 형변환하는 과정이라고 말할 수 있다. * django shell에서 실습해보자.python manage.py shell >>> from blog.models..